我想将 Monaco Editor 的版本升级到 v0.31.1。我做到了npm install monaco-editor@0.31.1
,并且重新编译sudo PORT=8000 HTTPS=true ./node_modules/.bin/react-app-rewired start
给了我以下错误:
Failed to compile.
./node_modules/monaco-editor/esm/vs/language/html/monaco.contribution.js 154:11
Module parse failed: Unexpected token (154:11)
File was processed with these loaders:
* ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
| dispose() {
| onLanguageListener.dispose();
> mode?.dispose();
| mode = void 0;
| }
有人可以帮忙吗?
编辑1:
package.json
升级前:
{
"name": "frontend",
"version": "0.1.0",
"private": true,
"dependencies": {
"@fluentui/react": "^8.33.0",
"@handsontable/react": "^9.0.2",
"@material-ui/core": "^4.9.8",
"@microsoft/office-js-helpers": "^1.0.2",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"@types/react-stripe-elements": "^6.0.4",
"@uifabric/react-cards": "^0.109.49",
"axios": "^0.19.2",
"color": "^3.1.2",
"copy-to-clipboard": "^3.3.1",
"cross-storage": "^1.0.0",
"dva": "^2.4.1",
"dva-model-creator": "^0.4.3",
"formik": "^2.1.4",
"handsontable": "^9.0.2",
"highcharts": "^7.0.3",
"highcharts-react-official": "^3.0.0",
"lodash": "^4.17.15",
"moment": "^2.24.0",
"monaco-editor": "^0.20.0",
"monaco-languageclient": "^0.13.0",
"node-sass": "^4.14.1",
"office-ui-fabric-core": "^11.0.0",
"office-ui-fabric-react": "^7.105.4",
"query-string": "^6.11.1",
"react": "^16.13.1",
"react-app-polyfill": "^1.0.6",
"react-bootstrap": "^1.0.1",
"react-dom": "^16.13.1",
"react-meta-tags": "^1.0.1",
"react-monaco-editor": "^0.35.0",
"react-scripts": "3.4.1",
"react-stripe-elements": "^6.1.1",
"redux-devtools-extension": "^2.13.8",
"styled-components": "^5.0.1",
"typescript": "^3.8.3",
"yup": "^0.28.3"
},
"scripts": {
"start": "PORT=3000 react-app-rewired start",
"start:https": "HTTPS=true react-app-rewired start",
"build": "react-scripts --max_old_space_size=8096 build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@types/color": "^3.0.1",
"@types/cross-storage": "^0.8.29",
"@types/jest": "^25.1.4",
"@types/lodash": "^4.14.149",
"@types/node": "^13.9.5",
"@types/office-js": "^1.0.92",
"@types/query-string": "^6.3.0",
"@types/react": "^16.9.27",
"@types/react-dom": "^16.9.5",
"@types/react-redux": "^7.1.7",
"@types/styled-components": "^5.0.1",
"@types/yup": "^0.26.33",
"css-loader": "^3.5.3",
"react-app-rewired": "^2.1.8",
"style-loader": "^1.2.1"
}
}
当"monaco-editor": "^0.20.0"
,npm list monaco-editor
返回
$ npm list monaco-editor
npm list monaco-editor
frontend@0.1.0 /frontend
├── UNMET DEPENDENCY monaco-editor@0.20.0
└─┬ UNMET DEPENDENCY react-monaco-editor@0.35.0
└── UNMET DEPENDENCY monaco-editor@0.20.0
npm ERR! missing: monaco-editor@0.20.0, required by frontend@0.1.0
npm ERR! missing: react-monaco-editor@0.35.0, required by frontend@0.1.0
npm ERR! missing: monaco-editor@0.20.0, required by react-monaco-editor@0.35.0
当"monaco-editor": "^0.31.1"
,npm list monaco-editor
返回
$ npm list monaco-editor
frontend@0.1.0 /frontend
├── UNMET DEPENDENCY monaco-editor@0.31.1
└─┬ UNMET DEPENDENCY react-monaco-editor@0.35.0
└── UNMET DEPENDENCY monaco-editor@0.31.1
npm ERR! missing: monaco-editor@0.31.1, required by frontend@0.1.0
npm ERR! missing: react-monaco-editor@0.35.0, required by frontend@0.1.0
npm ERR! missing: monaco-editor@0.31.1, required by react-monaco-editor@0.35.0
编辑2:
在@Bart 的anwser 之后,我安装并@babel/preset-env
使用yarn add @babel/preset-env --dev
创建babel.config.json
,{"presets": ["@babel/preset-env"]}
但react-app-rewired start
给出了同样的错误。
然后,我意识到我确实有一个文件config-overrides.js
,内容如下:
module.exports = function override (config, env) {
// disable chunks so the index.html won't change during development
config.optimization.splitChunks = {
cacheGroups: {
default: false,
},
};
config.optimization.runtimeChunk = false;
return config;
}
然后我添加了 的部分config.module.rules
,但编译返回了相同的错误。
此外,似乎可以在yarn build
没有此错误的情况下构建项目。但是构建项目需要时间。
module.exports = function override (config, env) {
config.module.rules =
[
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}
]
// disable chunks so the index.html won't change during development
config.optimization.splitChunks = {
cacheGroups: {
default: false,
},
};
config.optimization.runtimeChunk = false;
return config;
}