好吧,我正在尝试创建一个 react 应用程序,并想使用简单的 walletconnect 包并尝试创建我的 react 应用程序的构建文件,但是当我运行 webpack 命令来创建构建文件时出现模块错误我的应用程序。回溯如下:
ERROR in ./frontend/src/index.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: Cannot find module '@babel/preset-core'
Require stack:
- C:\Users\AHMED\Dotesrow\dotescrow\node_modules\@babel\core\lib\config\files\plugins.js
- C:\Users\AHMED\Dotesrow\dotescrow\node_modules\@babel\core\lib\config\files\index.js
- C:\Users\AHMED\Dotesrow\dotescrow\node_modules\@babel\core\lib\index.js
- C:\Users\AHMED\Dotesrow\dotescrow\node_modules\babel-loader\lib\index.js
- C:\Users\AHMED\Dotesrow\dotescrow\node_modules\loader-runner\lib\loadLoader.js
- C:\Users\AHMED\Dotesrow\dotescrow\node_modules\loader-runner\lib\LoaderRunner.js
- C:\Users\AHMED\Dotesrow\dotescrow\node_modules\webpack\lib\NormalModule.js
- C:\Users\AHMED\Dotesrow\dotescrow\node_modules\webpack\lib\NormalModuleFactory.js
- C:\Users\AHMED\Dotesrow\dotescrow\node_modules\webpack\lib\Compiler.js
- C:\Users\AHMED\Dotesrow\dotescrow\node_modules\webpack\lib\webpack.js
- C:\Users\AHMED\Dotesrow\dotescrow\node_modules\webpack\lib\index.js
- C:\Users\AHMED\Dotesrow\dotescrow\node_modules\webpack-cli\lib\webpack-cli.js
- C:\Users\AHMED\Dotesrow\dotescrow\node_modules\webpack-cli\lib\bootstrap.js
- C:\Users\AHMED\Dotesrow\dotescrow\node_modules\webpack-cli\bin\cli.js
- C:\Users\AHMED\Dotesrow\dotescrow\node_modules\webpack\bin\webpack.js
- If you want to resolve "@babel/core", use "module:@babel/core"
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
at resolve (C:\Users\AHMED\Dotesrow\dotescrow\node_modules\v8-compile-cache\v8-compile-cache.js:164:23)
at resolveStandardizedName (C:\Users\AHMED\Dotesrow\dotescrow\node_modules\@babel\core\lib\config\files\plugins.js:100:7)
at resolvePreset (C:\Users\AHMED\Dotesrow\dotescrow\node_modules\@babel\core\lib\config\files\plugins.js:48:10)
at loadPreset (C:\Users\AHMED\Dotesrow\dotescrow\node_modules\@babel\core\lib\config\files\plugins.js:67:20)
at createDescriptor (C:\Users\AHMED\Dotesrow\dotescrow\node_modules\@babel\core\lib\config\config-descriptors.js:154:9)
at C:\Users\AHMED\Dotesrow\dotescrow\node_modules\@babel\core\lib\config\config-descriptors.js:109:50
at Array.map (<anonymous>)
at createDescriptors (C:\Users\AHMED\Dotesrow\dotescrow\node_modules\@babel\core\lib\config\config-descriptors.js:109:29)
at createPresetDescriptors (C:\Users\AHMED\Dotesrow\dotescrow\node_modules\@babel\core\lib\config\config-descriptors.js:101:10)
webpack 5.13.0 compiled with 1 error in 1736 ms
babelrc
{
"presets": ["@babel/preset-env","@babel/preset-react","@babel/core"],
"plugins": ["transform-class-properties"]
}
package.json
{
"name": "dotescrow",
"version": "1.0.0",
"main": "webpack.config.js",
"scripts": {
"dev": "webpack --mode development frontend/src/index.js --output-path ./frontend/static/main.js",
"build": "webpack --mode production frontend/src/index.js --output-path ./frontend/static/main.js/main.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/AhmedYasin487/Dotescrow.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/AhmedYasin487/Dotescrow/issues"
},
"homepage": "https://github.com/AhmedYasin487/Dotescrow#readme",
"devDependencies": {
"@babel/core": "^7.12.10",
"@babel/preset-env": "^7.12.11",
"@babel/preset-react": "^7.12.10",
"babel-loader": "^8.2.2",
"babel-plugin-transform-class-properties": "^6.24.1",
"webpack": "^5.13.0",
"webpack-cli": "^4.3.1"
},
"dependencies": {
"@walletconnect/client": "^1.3.3",
"prop-types": "^15.7.2",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-native": "^0.63.4",
"walletconnect": "^1.3.3"
},
"description": ""
}
webpack.confi.js
const path = require('path')
module.exports = {
entry: path.resolve(__dirname, 'frontend/src', 'index.js'),
output: {
path: path.resolve(__dirname, 'frontend/static/main.js'),
filename: 'main.js'
},
mode:'development',
module: {
rules: [
{
test: /\.(jsx|js)$/,
// include: path.resolve(__dirname, 'frontend/src'),
exclude: /node_modules/,
use: {
loader: 'babel-loader',
}
]
},
}
视觉错误。
如果需要更多代码,请在评论中告诉我。我会用这些信息更新我的问题,谢谢。
答案 0 :(得分:0)
@babel/core
不是预设,请将其从 babelrc 的 presets
数组中删除。