Reactjs 网页包配置文件
我不熟悉使用React并尝试如下配置webpack.config.js文件:Reactjs 网页包配置文件,reactjs,webpack,Reactjs,Webpack,我不熟悉使用React并尝试如下配置webpack.config.js文件: import path from 'path' module.exports = { entry : './src/index.js', output: { path: path.resolve(__dirname, "public"), filename : 'bundle.js', }, mod
import path from 'path'
module.exports = {
entry : './src/index.js',
output: {
path: path.resolve(__dirname, "public"),
filename : 'bundle.js',
},
module:{
rules:[
{
test:/\.js$/,
exclude: /node_modules/,
loader:'babel-loader',
},
],
},
};
但是,当我尝试运行webpack命令以生成捆绑文件时,出现了以下错误:
必须使用导入加载ES模块:\webpack.config.js
我在此文件中未使用“require”,无法找到错误原因。
以下是我的部分套餐。jason:
{
"name": "fulljs",
"version": "1.0.0",
"type": "module",
"description": "Full JS Project",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon --exec babel-node server.js --ignore public/",
"dev": "webpack -wd "
},
我还使用as:
npm 6.14.4
webpack 4.43.0您需要使用:const path = require('path');
而不是:import path from 'path'
您需要使用:const path = require('path');
而不是:import path from 'path'
try
const path=require('path')
如果我使用const path=require('path'),则出现相同的错误tryconst path=require('path')
如果我使用const path=require('path'),则出现相同的错误如果我使用:const path=require('path'),则出现相同的错误