我正在使用React应用。
我收到此错误。
Module build failed (from ./node_modules/babel-loader/lib/index.js):
在此项目中,我使用了babel
和webpack
。
有些地方我缺少一些东西,无法运行该项目。
我的package.json
依旧。
"dependencies": {
"@babel/polyfill": "^7.7.0",
"@storybook/addon-backgrounds": "^3.4.8",
"@storybook/react": "^4.0.0-alpha.4",
"@types/d3": "^5.0.0",
"@types/debug": "^0.0.30",
"@types/enzyme": "^3.1.9",
"@types/jest": "^23.1.4",
"@types/moment-timezone": "^0.5.4",
"@types/react": "^16.0.38",
"@types/react-color": "^3.0.1",
"@types/react-copy-to-clipboard": "^4.2.6",
"@types/react-dom": "^16.0.4",
"@types/react-intl": "^2.3.16",
"@types/react-mentions": "2.4.0",
"@types/react-redux": "^6.0.3",
"@types/react-router": "^4.0.22",
"@types/react-router-dom": "^4.2.4",
"@types/react-select": "^1.2.6",
"@types/react-show-more": "^2.0.1",
"@types/redux": "^3.6.0",
"@types/redux-form": "^7.3.1",
"@types/redux-logger": "^3.0.6",
"@types/storybook__addon-backgrounds": "^3.2.0",
"@types/storybook__react": "^3.0.8",
"awesome-typescript-loader": "^5.2.0",
"axios": "^0.18.0",
"babel-register": "^6.26.0",
"connected-react-router": "^4.4.1",
"cosed": "^1.1.8",
"d3": "^5.7.0",
"date-fns": "^1.29.0",
"debug": "^3.1.0",
"duplicate-package-checker-webpack-plugin": "^3.0.0",
"emoji-mart": "^2.6.1",
"enzyme": "^3.3.0",
"enzyme-adapter-react-16": "^1.1.1",
"gen-tester": "^3.1.2",
"html-loader": "^0.5.5",
"husky": "^0.14.3",
"immer": "^1.3.1",
"jest": "^23.3.0",
"jest-environment-enzyme": "^6.0.2",
"jest-enzyme": "^6.0.2",
"jest-styled-components": "^5.0.1",
"lint-staged": "^7.2.0",
"moment-timezone": "^0.5.14",
"prettier": "^1.13.7",
"react": "^16.2.0",
"react-color": "^2.17.3",
"react-copy-to-clipboard": "^5.0.1",
"react-cosed": "^1.0.9",
"react-dom": "^16.2.0",
"react-intl": "^2.8.0",
"react-mentions": "^2.4.1",
"react-redux": "^5.0.7",
"react-router": "^4.2.0",
"react-router-dom": "^4.2.2",
"react-select": "^1.2.1",
"react-show-more": "^2.0.0",
"redux": "^4.0.0",
"redux-cosed": "^1.0.1",
"redux-form": "^7.4.2",
"redux-logger": "^3.0.6",
"redux-persist": "^5.10.0",
"redux-thunk": "^2.3.0",
"styled-components": "^3.1.6",
"ts-jest": "^23.0.0",
"tslint": "^5.9.1",
"tslint-config-prettier": "^1.13.0",
"tslint-no-circular-imports": "^0.5.0",
"typescript": "^2.7.2",
"uglifyjs-webpack-plugin": "^1.2.7",
"url-loader": "^1.0.1",
"webpack-merge": "^4.1.3"
},
"lint-staged": {
"*.{js,ts,tsx}": [
"prettier --write",
"git add"
]
},
"devDependencies": {
"@babel/core": "^7.7.2",
"@babel/plugin-proposal-class-properties": "^7.7.0",
"@babel/preset-env": "^7.7.1",
"@babel/preset-react": "^7.7.0",
"@types/lodash.debounce": "^4.0.4",
"babel-loader": "^8.0.6",
"firebase-tools": "^6.1.0",
"html-webpack-plugin": "^3.2.0",
"lodash.debounce": "^4.0.8",
"path": "^0.12.7",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.10",
"webpack-dev-server": "^3.9.0"
}
我的.babelrc
文件为...
{
"presets": [
[ "@babel/preset-env", {
"modules": false,
"targets": {
"browsers": [
"last 2 Chrome versions",
"last 2 Firefox versions",
"last 2 Safari versions",
"last 2 iOS versions",
"last 1 Android version",
"last 1 ChromeAndroid version",
"ie 11"
]
}
}],
"@babel/preset-react"
],
"plugins": [ "@babel/plugin-proposal-class-properties" ]
}
我的webpack/common.js
文件是...
require("@babel/polyfill");
const path = require('path');
const HtmlWebPackPlugin = require('html-webpack-plugin');
const {
CheckerPlugin,
TsConfigPathsPlugin,
} = require('awesome-typescript-loader');
const DuplicatePackageCheckerPlugin = require('duplicate-package-checker-webpack-plugin');
const ROOT = path.resolve(__dirname, '..');
module.exports = {
module: {
rules: [
{
test: /\.(ts|tsx)$/,
use: 'babel-loader',
exclude: /node_modules/,
},
{
test: /.(png|jpg|gif|svg)$/,
use: [
{
loader: 'url-loader',
options: {
limit: 25000,
},
},
],
},
{
test: /.html$/,
use: 'html-loader',
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
modules: [path.resolve(ROOT, 'shared'), 'node_modules'],
plugins: [new TsConfigPathsPlugin()],
},
plugins: [
new HtmlWebPackPlugin({
template: path.join(ROOT, 'shared', 'index.html'),
filename: './index.html',
}),
new DuplicatePackageCheckerPlugin(),
],
};
和webpack/dev.js
与...一样
require("@babel/polyfill");
const webpack = require('webpack');
const path = require('path');
const ROOT = path.resolve(__dirname, '..');
module.exports = {
mode: 'development',
devtool: 'inline-source-map',
devServer: {
contentBase: path.join(ROOT, 'dist'),
historyApiFallback: true,
port: 8080,
open: true,
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(process.env.NODE_ENV || 'development'),
API_BASE: JSON.stringify('application_url'),
},
}),
new webpack.optimize.OccurrenceOrderPlugin(true),
],
};
请提出一些更正...。 谢谢