npx create-react-app fails Must use import to load ES Module
See original GitHub issueDescribe the bug
npx create-react-app test --use-npm --template typescript
failes with following error
internal/modules/cjs/loader.js:1172
throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
^
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /home/apoorvmote/test/node_modules/is-promise/index.js
require() of ES modules is not supported.
require() of /home/apoorvmote/test/node_modules/is-promise/index.js from /home/apoorvmote/test/node_modules/run-async/index.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename /home/apoorvmote/test/node_modules/is-promise/index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /home/apoorvmote/test/node_modules/is-promise/package.json.
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1172:13)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Module.require (internal/modules/cjs/loader.js:1042:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (/home/apoorvmote/test/node_modules/run-async/index.js:3:17)
at Module._compile (internal/modules/cjs/loader.js:1156:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14) {
code: 'ERR_REQUIRE_ESM'
}
Aborting installation.
node has failed.
If I try to install with yarn create react-app test --template typescript
then I get following error
internal/modules/cjs/loader.js:584
if (e.code !== 'ERR_PACKAGE_PATH_NOT_EXPORTED') throw e;
^
Error [ERR_INVALID_PACKAGE_TARGET]: Invalid "exports" main target "index.js" defined in the package config /home/apoorvmote/.config/yarn/global/node_modules/is-promise/package.json
at resolveExportsTarget (internal/modules/cjs/loader.js:542:13)
at resolveExportsTarget (internal/modules/cjs/loader.js:581:20)
at applyExports (internal/modules/cjs/loader.js:455:14)
at resolveExports (internal/modules/cjs/loader.js:508:23)
at Function.Module._findPath (internal/modules/cjs/loader.js:632:31)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1001:27)
at Function.Module._load (internal/modules/cjs/loader.js:884:27)
at Module.require (internal/modules/cjs/loader.js:1074:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (/home/apoorvmote/.config/yarn/global/node_modules/run-async/index.js:3:17) {
code: 'ERR_INVALID_PACKAGE_TARGET'
}
error Command failed.
Did you try recovering your dependencies?
npm v 16.14.4 yarn v 1.22.4
Which terms did you search for in User Guide?
I searched exactly npx create-react-app not workin saw few old github issues.
Environment
Invalid "exports" main target "index.js" defined in the package config /home/apoorvmote/.config/yarn/global/node_modules/is-promise/package.json
Steps to reproduce
brew install node@12
npx create-react-app test --use-npm --template typescript
yarn create react-app test --template typescript
Expected behavior
I literally created new react project today morning and deployed to production. I don’t know why suddenly its not working anymore.
It doesn’t work in Ubuntu 18.04
, Ubuntu 20.04
and Windows 10 Pro
. Both Ubuntu running on WSL 2
Actual behavior
The error from windows 10 pro
internal/modules/cjs/loader.js:1172
throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
^
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: C:\Users\Admin\Desktop\test\node_modules\is-promise\index.js
require() of ES modules is not supported.
require() of C:\Users\Admin\Desktop\test\node_modules\is-promise\index.js from C:\Users\Admin\Desktop\test\node_modules\run-async\index.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename C:\Users\Admin\Desktop\test\node_modules\is-promise\index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from C:\Users\Admin\Desktop\test\node_modules\is-promise\package.json.
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1172:13)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Module.require (internal/modules/cjs/loader.js:1042:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (C:\Users\Admin\Desktop\test\node_modules\run-async\index.js:3:17)
at Module._compile (internal/modules/cjs/loader.js:1156:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14) {
code: 'ERR_REQUIRE_ESM'
}
Aborting installation.
node has failed.
Reproducible demo
(Paste the link to an example project and exact instructions to reproduce the issue.)
npx create-react-app test --use-npm --template typescript
yarn create react-app test --template typescript
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:9 (1 by maintainers)
Top GitHub Comments
Known bug, a dependency is broken, see https://github.com/facebook/create-react-app/issues/8896#issuecomment-619406384 for workaround.
Issue is fixed by
create-react-app
people. But I was stil having issue & not able to create react app.I am on Ubuntu 20.04 and this is what worked for me.
/home/username/.config/yarn/global/
node_modules
package.json
yarn.lock
node_modules
andyarn.lock
& keeppackage.json
withrm -rf node_modules
rm yarn.lock
npx create-react-app my-app