Babel - Error: Cannot find module 'babel-runti

2019-06-15 08:11发布

问题:

Transpiling via gulp-babel for the server and browserify with babelify for the client - using async and await in my code. These features seem to transform just fine, but... Error: Cannot find module 'babel-runtime/helpers/typeof'

Contents of .babelrc

{
  "presets": ["react", "es2015"],
  "plugins": [
    "transform-class-properties",
    "transform-async-to-generator",
    "transform-runtime"
  ]
}

Relevant contents of package.json

"babel-core": "6.3.13",
"babel-eslint": "4.1.6",
"babel-plugin-transform-async-to-generator": "6.3.13",
"babel-plugin-transform-class-properties": "6.3.13",
"babel-plugin-transform-runtime": "6.3.13",
"babel-preset-es2015": "6.3.13",
"babel-preset-react": "6.3.13",
"babelify": "7.2.0",
"browserify": "12.0.1",
"gulp-babel": "6.1.0",

I have found a few other mentions of this, many of which seem to lead here - https://github.com/babel/babel/issues/2954

But I am getting a 404 at the link above and indeed cannot see any issues related to babel - https://github.com/babel/babel/issues redirects to https://github.com/babel/babel/pulls

Any ideas?

回答1:

Turns out I needed to take the install of babel-runtime, which I thought had been deprecated with the release of Babel v6.



回答2:

When I faced this, it was my version of npm. I had new installation of Ubuntu 16.04 and had used nodenv to get node 4.2.3 going, but hadn't updated npm from whatever default I had. So using npm update -g npm changed from version 2.14.7 to 3.10.5. I deleted node_modules and ran npm i again, and I did not see the error message after that. (Note that deleting node_modules and running npm i without updating npm didn't work.)



回答3:

installing babel-helpers solved the problem for me. npm install --save babel-helpers



回答4:

Looks like they have migrated all issues to another system: https://phabricator.babeljs.io/T2954



回答5:

I was facing this error and was up whole night to find a solution, in the end just deleted node_modules folder, did npm install and it worked



回答6:

I had a similar problem:

error in cannot find module 'babel-runtime/helpers/interop-require-default'

The way I dealt with it is to:

  1. delete node_modules folder
  2. re npm install, and it works this time


回答7:

I Had more or less similar kind of error

"Cannot find module 'babel-generator'. Had no clue on how to debug them. So I finally decided to

  1. Delete the Node Modules, Sometimes the (windows 'del node_modules' command does not delete the node_modules) in that case ,delete them manually.

  2. npm cache clean --force

  3. npm cache clear --force

  4. npm prune

  5. npm install

this approach did work for me.