Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Use module.createRequire() to fix using require() in ESM build #94

Closed
DrJume opened this issue Dec 14, 2021 · 0 comments · Fixed by #97
Closed

Use module.createRequire() to fix using require() in ESM build #94

DrJume opened this issue Dec 14, 2021 · 0 comments · Fixed by #97

Comments

@DrJume
Copy link

DrJume commented Dec 14, 2021

The ESM build is not able to run readFile() correcly, because require('fs') is used. require() is not avaiable in ESM.

require('fs').readFile(filename, 'utf8', callback);

The only thing missing, is to add

import { createRequire } from 'module';
const require = createRequire(import.meta.url);

to index.js.

@DrJume DrJume changed the title Use createRequire() for working require() in ESM build Use module.createRequire() for working require() in ESM build Dec 14, 2021
@DrJume DrJume changed the title Use module.createRequire() for working require() in ESM build Use module.createRequire() to fix using require() in ESM build Dec 14, 2021
DrJume added a commit to DrJume/vite-ssg that referenced this issue Dec 14, 2021
* temporary workaround for Critters using custom CrittersClassWithFS (GoogleChromeLabs/critters#94)

antfu-collective#145
developit added a commit that referenced this issue Jan 5, 2022
This should fix #94 in both CJS and ESM bundles.
@developit developit mentioned this issue Jan 5, 2022
developit added a commit that referenced this issue Jan 5, 2022
This should fix #94 in both CJS and ESM bundles.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant