【发布时间】:2023-04-11 08:06:02
【问题描述】:
我正在关注this tutorial 在Visual Studio 中创建一个react.js 应用程序
我正处于打开命令提示符并运行的步骤:
webpack app.tsx --config webpack-config.js
(我已经在node_modules.bin\目录下)
我得到错误:
C:\Users\user.user\Documents\Visual Studio 2019\Projects\WeatherApp\WeatherApp\node_modules\webpack\bin\webpack.js:11 const runCommand = (command, args) => { ^ module.js:434 var compiledWrapper = runInThisContext(wrapper, filename, true); ^ SyntaxError: Unexpected token > 在 Module._compile (module.js:434:25) 在 Object..js (module.js:464:10) 在 Module.load (module.js:353:31) 在 Function._load (module.js:311:12) 在 Array.0 (module.js:484:10) 在 EventEmitter._tickCallback (node.js:190:38)
这是我的 package.json 文件:
{
"name": "weather-app",
"version": "0.0.0",
"description": "WeatherApp",
"main": "server.js",
"author": {
"name": ""
},
"dependencies": {
"eslint": "^5.16.0",
"express": "^4.16.4",
"path": "^0.12.7",
"prettier": "^1.17.0",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"ts-loader": "^5.4.4",
"typescript": "^3.3.4000",
"webpack": "^4.30.0",
"webpack-cli": "^3.3.0"
}
}
这些版本比教程中指示的版本更新,否则我已经按照指示完成了所有操作。我的机器上安装了 node.js 10.15.3。
tsconfig.json文件内容:
{
"compilerOptions": {
"noImplicitAny": false,
"module": "commonjs",
"noEmitOnError": true,
"removeComments": false,
"sourceMap": true,
"pretty": true,
"allowJs": true,
"checkJs": true,
"target": "es5",
"jsx": "react"
},
"exclude": [
"node_modules"
],
"files": [
"app.tsx"
]
}
webpack-config.js:
module.exports = {
devtool: 'source-map',
entry: "./app.tsx",
mode: "development",
output: {
filename: "./app-bundle.js"
},
resolve: {
extensions: ['.Webpack.js', '.web.js', '.ts', '.js', '.jsx', '.tsx']
},
module: {
rules: [
{
test: /\.tsx$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'ts-loader'
}
}
]
}
}
我正在尝试弄清楚如何解决和/或解决此问题。有什么想法吗?
【问题讨论】:
-
您是否偶然安装了旧版本的 node.js 而不是现代版本?
-
@WiktorZychla 我安装了最新的 LTS 版本:10.15.3。
标签: node.js reactjs typescript visual-studio-2019