0

我正在通过 React 运行一个项目,“@codingame/monaco-languageclient”:“^0.17.3”,“monaco-editor”:“^0.31.1”和“react-monaco-editor”:“^0.35。 0”。编译给出了以下错误:

Failed to compile.

./node_modules/vscode-languageclient/lib/common/client.js
Module not found: Can't resolve 'vscode' in '/Users/SoftTimur/10Studio/frontend/node_modules/vscode-languageclient/lib/common'

我找到了这个线程,并且确实'vscode': require.resolve('monaco-languageclient/lib/vscode-compatibility')有他们webpack.config.js例子

然后我添加'vscode': require.resolve('@codingame/monaco-languageclient/lib/vscode-compatibility'),alias. node_modules/react-scripts/config/webpack.config.js它确实解决了错误。

但是,问题是如果我重新安装项目,我必须再次添加。有谁知道是否有自动注入'vscode': require.resolve('@codingame/monaco-languageclient/lib/vscode-compatibility'),alias方式node_modules/react-scripts/config/webpack.config.js

PS:我已经在使用 react-app-rewired 了。

4

1 回答 1

0

我们解决它的方式。它不是很优雅,但它确实有效。

添加一个名为 craco 的依赖项:

"@craco/craco": "^6.4.2",

然后你创建一个配置:craco.config.js

常量路径 = 要求(path);

module.exports = {
    webpack: {
        alias: {
            vscode: "@codingame/monaco-languageclient/lib/vscode-compatibility",
        },
    },
};

然后在 package.json 你改变脚本部分如下:

"scripts": {
        "start": "craco start",
        "build": "cracox build",
        "test": "craco test",
        "eject": "craco eject"
    },
于 2022-01-24T20:09:39.180 回答