Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

npx create-react-app fails Must use import to load ES Module #8897

Closed
apoorvmote opened this issue Apr 25, 2020 · 9 comments
Closed

npx create-react-app fails Must use import to load ES Module #8897

apoorvmote opened this issue Apr 25, 2020 · 9 comments

Comments

@apoorvmote
Copy link

Describe 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

  1. brew install node@12
  2. npx create-react-app test --use-npm --template typescript
  3. 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

@whoisdominic
Copy link

learning react for the first time today, im having the same issue

@barckcode
Copy link

barckcode commented Apr 25, 2020

I have this problem too:
`➜ npx create-react-app my-app
npx: instaló 99 en 6.25s
Must use import to load ES Module: /Users/cristianandrescordovavalencia/.npm/_npx/4026/lib/node_modules/create-react-app/node_modules/is-promise/index.js
require() of ES modules is not supported.
require() of /Users/cristianandrescordovavalencia/.npm/_npx/4026/lib/node_modules/create-react-app/node_modules/is-promise/index.js from /Users/cristianandrescordovavalenci
a/.npm/_npx/4026/lib/node_modules/create-react-app/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 /Users/cristianandrescordovavalencia/.npm/_npx/4026/lib/node_modules/create-react-app/node_modules/is-promise/index.js to end in .cjs, change the requiring c
ode to use import(), or remove "type": "module" from /Users/cristianandrescordovavalencia/.npm/_npx/4026/lib/node_modules/create-react-app/node_modules/is-promise/package.j
son.

~ took 7s
➜ npx create-react-app test --use-npm
npx: instaló 99 en 3.81s
Must use import to load ES Module: /Users/cristianandrescordovavalencia/.npm/_npx/4064/lib/node_modules/create-react-app/node_modules/is-promise/index.js
require() of ES modules is not supported.
require() of /Users/cristianandrescordovavalencia/.npm/_npx/4064/lib/node_modules/create-react-app/node_modules/is-promise/index.js from /Users/cristianandrescordovavalenci
a/.npm/_npx/4064/lib/node_modules/create-react-app/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 /Users/cristianandrescordovavalencia/.npm/_npx/4064/lib/node_modules/create-react-app/node_modules/is-promise/index.js to end in .cjs, change the requiring c
ode to use import(), or remove "type": "module" from /Users/cristianandrescordovavalencia/.npm/_npx/4064/lib/node_modules/create-react-app/node_modules/is-promise/package.j
son.

~ took 4s
➜ `

My SO:
macOS Catalina 10.15.4

~
➜ node -v
v12.16.2

~
➜ npm -v
6.14.4

~
➜ npx -v
6.14.4

~

I try uninstall and install node and npm but it doesn't work.


I only use npm. I don't have yarn installed to avoid conflicts.

@itxtoledo
Copy link

same issue today 25 april

@joonassiren
Copy link

same, pipeline builds started failing today all of a sudden due to this

@TheKobeCode
Copy link

Same issue, tried cleaning the npm cache, uninstalling and installing node, the recommended and the LTS version, and deleting the "type": "module" line on the file provided on the instructions and nothing works. I tried it with npx and the create-react-app command installed globally and it doesn't work.

@lex111
Copy link
Contributor

lex111 commented Apr 25, 2020

For maintainers: see then/is-promise#13 for more details.

@Xekram
Copy link

Xekram commented Apr 25, 2020

same issue today 25 april, i tried the install npm install - g create-react-app and it doesn't work
internal/modules/cjs/loader.js:616
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 /C:/Users/marlo/AppData/Roaming/npm/node_modules/create-react-app/node_modules/is-promise\package.json
at resolveExportsTarget (internal/modules/cjs/loader.js:574:13)
at resolveExportsTarget (internal/modules/cjs/loader.js:613:20)
at applyExports (internal/modules/cjs/loader.js:503:14)
at resolveExports (internal/modules/cjs/loader.js:541:12)
at Function.Module._findPath (internal/modules/cjs/loader.js:661:22)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:963:27)
at Function.Module._load (internal/modules/cjs/loader.js:859:27)
at Module.require (internal/modules/cjs/loader.js:1036:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object. (C:\Users\marlo\AppData\Roaming\npm\node_modules\create-react-app\node_modules\run-async\index.js:3:17) {
code: 'ERR_INVALID_PACKAGE_TARGET'
}

@RyanZim
Copy link

RyanZim commented Apr 25, 2020

Known bug, a dependency is broken, see #8896 (comment) for workaround.

@apoorvmote
Copy link
Author

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.

  • First uninstall node and yarn and reinstall again this may fix problem for most of you
  • If problem still persists then go to /home/username/.config/yarn/global/
  • You will find 3 different file or folders here
    1. node_modules
    2. package.json
    3. yarn.lock
  • then remove node_modules and yarn.lock & keep package.json with
    1. rm -rf node_modules
    2. rm yarn.lock
  • Then you are done. Just continue with npx create-react-app my-app

@lock lock bot locked and limited conversation to collaborators May 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants