找不到模块'@ babel / parser'

时间:2018-10-11 17:14:48

标签: javascript npm babeljs

运行babel时,我不再能够转换我的代码库。我做了。以前没有发生过,我不知道为什么。这仅在我拉出具有yarn.lock冲突的远程主分支时发生。我解决了与yarn命令的冲突。

这是我的package.json

的一部分
{
  "devDependencies": {
    "@babel/cli": "^7.1.0",
    "@babel/core": "^7.1.2",
    "@babel/plugin-proposal-class-properties": "^7.0.0",
    "@babel/plugin-proposal-decorators": "^7.0.0",
    "@babel/plugin-proposal-export-default-from": "^7.0.0",
    "@babel/plugin-proposal-export-namespace-from": "^7.0.0",
    "@babel/plugin-proposal-function-sent": "^7.0.0",
    "@babel/plugin-transform-runtime": "^7.1.0",
    "@babel/polyfill": "^7.0.0",
    "@babel/preset-env": "^7.1.0",
    "@babel/preset-react": "^7.0.0",
    "@babel/register": "^7.0.0",
    ...
  }
}

运行babel src -d build会导致以下错误

{ Error: Cannot find module '@babel/parser'
    at Function.Module._resolveFilename (module.js:548:15)
    at Function.Module._load (module.js:475:25)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)
    at _parser (/Users/mohammadmohammad/Dev/work/procore/hydra_clients/budgetViewer/node_modules/@babel/core/lib/transformation/normalize-file.js:59:16)
    at parser (/Users/mohammadmohammad/Dev/work/procore/hydra_clients/budgetViewer/node_modules/@babel/core/lib/transformation/normalize-file.js:170:18)
    at normalizeFile (/Users/mohammadmohammad/Dev/work/procore/hydra_clients/budgetViewer/node_modules/@babel/core/lib/transformation/normalize-file.js:138:11)
    at runSync (/Users/mohammadmohammad/Dev/work/procore/hydra_clients/budgetViewer/node_modules/@babel/core/lib/transformation/index.js:44:43)
    at runAsync (/Users/mohammadmohammad/Dev/work/procore/hydra_clients/budgetViewer/node_modules/@babel/core/lib/transformation/index.js:35:14)
    at /Users/mohammadmohammad/Dev/work/procore/hydra_clients/budgetViewer/node_modules/@babel/core/lib/transform-file.js:58:36 code: 'MODULE_NOT_FOUND' }

我还尝试删除node_modules并运行yarn install,但是没有运气。

3 个答案:

答案 0 :(得分:2)

只需将babel-eslint8.2,3撞到10.0.1就能解决问题

答案 1 :(得分:0)

这对我有用:

yarn add -D @babel/parser

OR 与 NPM

npm i -D @babel/parser

祝你好运...

答案 2 :(得分:0)

以下命令对我有用

npm 审计修复 --force

请注意,审计修复会安装 SemVer 对顶级依赖项的主要更新,而不仅仅是 SemVer 兼容的更新 (https://docs.npmjs.com/cli/v7/commands/npm-audit)