【问题标题】:Trying to run babel : "cannot find module @babel/core"尝试运行 babel:“找不到模块 @babel/core”
【发布时间】:2020-04-18 11:09:57
【问题描述】:

我正在尝试建立一个构建环境来探索反应。 我的构建过程使用 gulp。

我安装了这样的包:

npm install --save-dev gulp-babel@7 babel-core babel-preset-env

在发现我需要安装一些与 babel 相关的东西并做出反应后,我也跑了:

npm install --save-dev @babel/preset-react

我的 .babelrc 有这个:

{ "预设": ["@babel/preset-react"] }

我的 gulpfile 有这个:

gulp.task('scripts', function() {
    return gulp.src(['./src/js/main.js' ])
        .pipe(babel({
            presets : ['@babel/preset/react']
        }))
        .pipe(concat('test.js'))
        .pipe(gulp.dest('./js'))
        .pipe(uglify())
        .pipe(rename('test.min.js'))
        .pipe(gulp.dest('./js')) ;
});

当我运行“gulp 脚本”时,我得到了这个:

[22:51:14] Using gulpfile ~/play/learning-react-2/gulpfile.js
[22:51:14] Starting 'scripts'...
[22:51:14] 'scripts' errored after 59 ms
[22:51:14] Error in plugin "gulp-babel"
Message:
    Cannot find module '@babel/core' (While processing preset: "/home/bob/play/learning-react-2/node_modules/@babel/preset-react/lib/index.js")

我从 node_modules 中删除了 babel-core,然后使用命令重新安装了它:

npm install --save-dev @babel/core

如果我查看 node_modules 的内容,我会看到这些与 babel 相关的包:

babel-code-frame/
babel-helper-builder-binary-assignment-operator-visitor/ babel-helper-call-delegate/
babel-helper-define-map/
babel-helper-explode-assignable-expression/
babel-helper-function-name/
babel-helper-get-function-arity/
babel-helper-hoist-variables/
babel-helper-optimise-call-expression/
babel-helper-regex/
babel-helper-remap-async-to-generator/
babel-helper-replace-supers/
babel 消息/
babel-plugin-check-es2015-constants/
babel-plugin-syntax-async-functions/
babel-plugin-syntax-exponentiation-operator/
babel-plugin-syntax-trailing-function-commas/
babel-plugin-transform-async-to-generator/
babel-plugin-transform-es2015-arrow-functions/
babel-plugin-transform-es2015-block-scoped-functions/
babel-plugin-transform-es2015-block-scoping/
babel-plugin-transform-es2015-classes/
babel-plugin-transform-es2015-computed-properties/
babel-plugin-transform-es2015-destructuring/
babel-plugin-transform-es2015-duplicate-keys/
babel-plugin-transform-es2015-for-of/
babel-plugin-transform-es2015-function-name/
babel-plugin-transform-es2015-literals/
babel-plugin-transform-es2015-modules-amd/
babel-plugin-transform-es2015-modules-commonjs/
babel-plugin-transform-es2015-modules-systemjs/
babel-plugin-transform-es2015-modules-umd/
babel-plugin-transform-es2015-object-super/
babel-plugin-transform-es2015-parameters/
babel-plugin-transform-es2015-shorthand-properties/
babel-plugin-transform-es2015-spread/
babel-plugin-transform-es2015-sticky-regex/
babel-plugin-transform-es2015-template-literals/
babel-plugin-transform-es2015-typeof-symbol/
babel-plugin-transform-es2015-unicode-regex/
babel-plugin-transform-exponentiation-operator/
babel-plugin-transform-regenerator/
babel-plugin-transform-strict-mode/
babel-preset-env/
babel-runtime/
babel-模板/
通天塔遍历/ babel-types/

我猜其中至少有一个是“babel core”

那么...我实际上如何从 gulp 运行 babel?我该如何运行它?

【问题讨论】:

  • 请安装@babel/babel-core@babel/preset-env。据我所知,babel 在前缀 @babel 下发布了新包
  • @JosefBiehler '@babel/babel-core' 与'babel-core' 不同吗? '@babel/preset-env' 与 'babel-preset-env' 有什么不同吗?我已经安装了后一个包,但尝试安装前一个包失败 - 找不到它们。如果您描述的软件包与我安装的软件包不同,请告诉我如何安装。
  • @JosefBiehler 在没有进一步指导的情况下,我无法判断我是否安装了您指示我访问的软件包(在这种情况下它们根本不起作用)或者我是否安装了近- 相同的名字。
  • 当然包是不同的。请看一下例如npmjs.com/package/babel-core 。该软件包已于 2 年前更新。 preset-env 也是如此。我已经成功测试了npm install --save @babel/core @babel/preset-env。不小心写错了包名。必须是 @babel/core 而不是 @babel/babel-core
  • @JosefBiehler 好的 - 首先我删除了“node_modules”。然后我运行'npm install --save @babel/core @babel/preset-env'。我还重新安装了 gulp 模块。然后我运行这个:'./node_modules/.bin/babel src/js --out-dir js'。这可以按预期工作。但是,当我运行 'gulp' 时,我得到“错误:找不到模块 'babel-core'。所以问题一定与 gulp 方面有关。

标签: babeljs


【解决方案1】:

我有同样的问题。我通过删除node_modules 解决了它并重新安装了软件包(使用yarnnpm install)。问题已解决。

【讨论】:

    猜你喜欢
    • 2019-02-03
    • 2019-10-10
    • 2021-09-10
    • 2019-02-17
    • 2017-10-13
    • 1970-01-01
    • 2020-04-02
    • 2021-03-03
    • 1970-01-01
    相关资源
    最近更新 更多