【发布时间】:2023-04-11 05:00:01
【问题描述】:
之前遇到过这个错误,看到了其他答案,但是解决方案并没有解决我的问题。
在我的 package.json 中有:
"dependencies": {
"axios": "^0.15.2",
"babel": "^6.5.2",
"babel-core": "^6.13.1",
"babel-loader": "^6.0.1",
"babel-preset-es2015": "^6.0.15",
"babel-preset-node5": "^11.1.0",
"babel-preset-react": "^6.0.15",
"babel-preset-stage-0": "^6.0.15",
"babel-preset-stage-2": "^6.11.0",
然后在我的 webpack.config.js 我有:
module.exports = {
entry: './main.js',
然后在我的 main.js 中我有:
import "./src";
然后我运行 npm test 调用此脚本:
"scripts": {
"test": "mocha src/**/*.spec.js",
然后它失败了,因为在 src/components/header/index.spec.js:1 我有:import React from 'react';
不知道为什么它不起作用
我有一个.babelrc 文件,其中包含:
{
"sourceMaps": true,
"presets": ["es2015", "react", "stage-2"]
}
在我的 webpack 中我也有:
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel',
query: {
presets: ['es2015', 'react', 'stage-2']
}
},
{
test: /\.scss$/,
loaders: ["style-loader", "css-loader", "sass-loader"]
}
]
}
有什么想法吗?
【问题讨论】:
标签: javascript node.js reactjs import babeljs