Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Package exports for <path to project folder>/node_modules/@babel/helper-compilation-targets' do not define a '.' subpath

I just created a new project folder and ran the following commands:

  • npm init
  • npm install express
  • npm install express-react-views react react-dom

Created index.js with express imported and views for a sample jsx file. When I run on localhost, I get this error:

Error: Package exports for '<path_to_project_folder>/node_modules/@babel/helper-compilation-targets' do not define a '.' subpath
    at applyExports (internal/modules/cjs/loader.js:485:15)
    at resolveExports (internal/modules/cjs/loader.js:508:12)
    at Function.Module._findPath (internal/modules/cjs/loader.js:577:20)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:879:27)
    at Function.Module._load (internal/modules/cjs/loader.js:785:27)
    at Module.require (internal/modules/cjs/loader.js:956:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (<path_to_project_folder>/node_modules/@babel/preset-env/lib/debug.js:8:33)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Module._compile (<path_to_project_folder>/node_modules/pirates/lib/index.js:99:24)

In Oct 2019, I created an express app using the same steps ran, and found there is no such package (@babel/helper-compilation-targets), and it ran fine.

I'm not sure what is wrong. Can anyone help to advice? Thank you!

like image 684
sltan Avatar asked Jan 12 '20 17:01

sltan


3 Answers

Had the same issue. Updating the node.js fixed that for me

like image 126
Nikita Avatar answered Oct 19 '22 17:10

Nikita


So this seems to be an incompatibility between Babel and Node.js. The general solution is to switch to nodejs 12 (e.g. if you are using nvm), since it only affected nodejs 13:

nvm install 12
nvm use 12

However, for my Rails 6 application this was not sufficient alone, as I still got the same error. Telling Yarn about the node version I am expecting to use was necessary in addition to that. So I added this to the package.json:

"engines": {
  "node": "12.14.1"
}
like image 39
NobodysNightmare Avatar answered Oct 19 '22 17:10

NobodysNightmare


It will be fixed on babel v7.8.4, see https://github.com/babel/babel/pull/11006. Before a new babel release is cut, please upgrade node.js to >=13.2.0, which incorporates the necessary upstream fix.

Note that node.js 12 is not affected unless you have manually toggled on --experimental-modules flag. If that is the case, please also upgrade node.js to >=13.2.0.

like image 6
JLHwung Avatar answered Oct 19 '22 17:10

JLHwung