【问题标题】:Cannot find module '@babel/parser'找不到模块'@babel/parser'
【发布时间】:2018-10-11 17:14:47
【问题描述】:

在运行 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,但没有成功。

【问题讨论】:

  • 您是否删除了锁定的包 json 文件?
  • 这可能是个愚蠢的问题,但为什么不yarn add @babel/parser
  • @JoeFitzsimmons 我没有。我检查了yarn.lock@babel/parser 确实存在
  • @ChrisG babel/parser 是 babel/core 中的一个依赖项,我不应该或直接在我的项目中安装它。
  • @ChrisG,我检查了所有的 cmets 甚至解决方案,但它不适用于我的情况,但你的情况可以。谢谢。

标签: javascript npm babeljs


【解决方案1】:

只需将babel-eslint8.2,3 碰撞到10.0.1 即可解决问题

【讨论】:

  • 你应该将此答案标记为正确的解决方案然后
【解决方案2】:

这对我有用:

yarn add -D @babel/parser

或与NPM

npm i -D @babel/parser

祝你好运……

【讨论】:

    【解决方案3】:

    以下命令对我有用

    npm 审计修复 --force

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

    【讨论】:

      猜你喜欢
      • 2019-02-03
      • 2021-03-03
      • 2019-07-30
      • 2019-03-24
      • 2021-11-04
      • 2020-10-09
      • 2019-02-17
      • 1970-01-01
      • 2016-03-23
      相关资源
      最近更新 更多