reactjs - 由于神秘的语法错误,NPM 无法构建
问题描述
我正在尝试学习 React,但构建并没有组合在一起。当我尝试“npm run build”时,我得到了这个:
Version: webpack 3.1.0
Time: 202ms
Asset Size Chunks Chunk Names
bundle.js 3.5 kB 0 [emitted] main
[0] ./src/app.js 738 bytes {0} [built] [failed] [1 error]
ERROR in ./src/app.js
Module build failed: SyntaxError: Unexpected token (5:16)
3 | import IndecisionApp from "./components/IndecisionApp";
4 |
> 5 | ReactDOM.render(<IndecisionApp />, document.getElementById('app'));
| ^
我的 package.json:
{
"name": "indecision-app2",
"version": "1.0.0",
"main": "index.js",
"author": "some person",
"license": "MIT",
"description": "",
"scripts": {
"serve": "live-server public/",
"build": "webpack",
"dev-server": "webpack-dev-server"
},
"dependencies": {
"babel-cli": "6.24.1",
"babel-core": "6.25.0",
"babel-loader": "7.1.1",
"babel-preset-env": "1.5.2",
"babel-preset-react": "6.24.1",
"live-server": "^1.2.0",
"react": "15.6.1",
"react-dom": "15.6.1",
"validator": "8.0.0",
"webpack": "3.1.0",
"webpack-dev-server": "^2.5.1"
}
}
我的 webpack.config.js:
const path = require('path');
module.exports = {
entry: './src/app.js',
output: {
path: path.join(__dirname, 'public'),
filename: "bundle.js"
},
module: {
rules: [{
loader: 'babel-loader',
test: /\.js$/,
exclude: /node_modules/
}]
},
devtool: 'cheap-module-eval-source-map',
devServer: {
contentBase: path.join(__dirname, 'public')
}
};
我的 app.js:
import React from "react";
import ReactDOM from "react-dom";
import IndecisionApp from "./components/IndecisionApp";
ReactDOM.render(<IndecisionApp />, document.getElementById('app'));
有人可以帮我理解什么是错的吗?这不应该建吗?几周前,同样的语法也奏效了。
解决方案
推荐阅读
- angular - TypeError 中的错误:执行 ng serve 时无法读取未定义的属性“标志”
- mysql - MySQL“错误1262(01000):第1行被截断;它包含的数据多于输入列”这是为什么?
- hibernate - 使用 JPA 通过联合生成的访问视图
- apk - 执行 msfvenom 时如何解决此错误?
- c - 通过子进程和未命名的 posix 信号量增加计数器变量不起作用
- microsoft-graph-api - 首选副本不可用 - Microsoft Graph
- python - 我正在尝试使用 PANDAS 按日期排序,但不起作用,总是读取字符串
- java - Flutter build apk 命令抛出错误并且没有构建 apk
- java - 无法使用基本映像 debian:buster 安装 openjdk-13-jdk-headless=13~30-1
- django - 与 Django 一起运行 TCP 服务器以收集物联网数据的最佳方式