以下是我的webpack4/react教程:

https://www.youtube.com/watch?v=deyxI-6C2u4

我一直跟踪到他运行npm的那部分开始.不同的是,他的应用程序运行,而我的则出现错误:

找不到模块"@babel/core"

完整错误:

ERROR in ./src/index.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: 找不到模块"@babel/core"
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (C:\Users\joeyf\Desktop\Code\Github\webpack4-sample\node_modules\babel-loader\lib\index.js:5:15)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
 @ multi (webpack)-dev-server/client?http://localhost:8080 (webpack)/hot/dev-server.js ./src/index.js main[2]

我试图重新安装巴别塔核心,但仍然没有找到.这是我的Package.json:

{
  "name": "webpack4-sample",
  "version": "1.0.0",
  "description": "A sample setup of Webpack4 with React and Babel",
  "main": "index.js",
  "scripts": {
    "start": "webpack-dev-server --mode development --open --hot",
    "build": "webpack --mode production"
  },
  "author": "Joey Fenny",
  "license": "ISC",
  "dependencies": {
    "babel": "^6.23.0",
    "babel-cli": "^6.26.0",
    "react": "^16.4.2",
    "react-dom": "^16.4.2"
  },
  "devDependencies": {
    "babel-core": "^7.0.0-rc.4",
    "babel-loader": "^8.0.0",
    "babel-preset-env": "^1.7.0",
    "babel-preset-react": "^6.24.1",
    "html-webpack-plugin": "^3.2.0",
    "webpack": "^4.17.1",
    "webpack-cli": "^3.1.0",
    "webpack-dev-server": "^3.1.6"
  }
}

我的网页包.配置.js:

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
    entry: './src/index.js',
    output: {
        path: path.join(__dirname, '/dist'),
        filename: 'index_bundle.js'
    },
    module: {
        rules: [{
            test: /\.js$/,
            exclude: path.join(__dirname, '/node_modules'),
            use: {
                loader: 'babel-loader'
            }
        }]
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: './src/index.html'
        })
    ]
}

以下是git回购协议的链接:

https://gitlab.com/jfny/webpack4-sample

有人知道发生了什么吗?谢谢

推荐答案

试着运行这个.

npm install @babel/core --save

巴贝尔改变了他们的套餐,所以你的babel-core@babel/core不一样.

Node.js相关问答推荐

无法在我的 node 项目中转让Google Drive v3 API中的所有权

在导入时未找到Pupeteer-PAGE-Proxy包

如何使用MongoDB在Node.js 中向数组中添加项?

Mongoose更新在^8.0.3版中,许多似乎不能按预期工作

Firebase-admin筛选器.或只考虑第一个WHERE子句

使用ReadableStream.管道时NodeJS Crypto Hash不正确

聚合操作不返回任何具有mongoose模式的内容

仅在一次查询中 MongoDB 上最近的一对位置

Node.js 连接在查询完成之前终止

如何在Node.js的telegraf.js命令中添加参数?

node-gyp: "..\src\binding.cc: 没有这样的文件或目录"

Nodejs mongoose 在一个查询中从多个集合中获取结果

如何在不使用位置运算符 $ 的情况下更新 mongodb 文档中数组中的嵌套文档?

NestJS 共享模块的问题

node.js 变量不存在代码块

Node.js + Express 上的多个视图路径

TypeError:winston.Logger 不是带有winston 和morgan 的构造函数

Node.js 支持 =>(箭头函数)

需要 node-gyp 的 npm install 在 Windows 上失败

Route.get() 需要回调函数,但得到对象未定义