无法读取未定义的属性“thisCompilation”-react-scripts-ts

IT技术 javascript reactjs typescript webpack create-react-app
2021-05-01 05:21:44

我创建了一个新项目,使用以下说明完全空白:https : //developer.microsoft.com/en-us/fabric#/get-started 按照步骤 1-4

该应用程序运行良好。

一旦我运行 npm i webpack

然后我收到这个错误

我的 package.json

{
"name": "lulo",
"version": "0.1.0",
"private": true,
"dependencies": {
"office-ui-fabric-react": "^6.157.0",
"react": "^16.8.4",
"react-adal": "^0.4.22",
"react-dom": "^16.8.4",
"react-scripts-ts": "3.1.0",
"redux": "^4.0.1"
},
"scripts": {
"start": "react-scripts-ts start",
"build": "react-scripts-ts build",
"test": "react-scripts-ts test --env=jsdom",
"eject": "react-scripts-ts eject"
},
"devDependencies": {
"@types/jest": "^24.0.11",
"@types/node": "^11.11.3",
"@types/react": "^16.8.8",
"@types/react-adal": "^0.4.1",
"@types/react-dom": "^16.8.2",
"typescript": "^3.3.3333",
"webpack": "^4.29.6",
"webpack-cli": "^3.3.0"
}
}

错误是这样的:

  Creating an optimized production build...
Starting type checking and linting service...
Using 1 worker with 2048MB memory limit
Failed to compile.

Cannot read property 'thisCompilation' of undefined


npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! lulo@0.1.0 build: `react-scripts-ts build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the lulo@0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/luisvalencia/.npm/_logs/2019-03-19T21_18_01_997Z-debug.log

和日志文件有这个

0 info it worked if it ends with ok
1 verbose cli [ '/Users/x/.nvm/versions/node/v10.0.0/bin/node',
1 verbose cli   '/Users/x/.nvm/versions/node/v10.0.0/bin/npm',
1 verbose cli   'run-script',
1 verbose cli   'build' ]
2 info using npm@5.6.0
3 info using node@v10.0.0
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle lulo@0.1.0~prebuild: lulo@0.1.0
6 info lifecycle lulo@0.1.0~build: lulo@0.1.0
7 verbose lifecycle lulo@0.1.0~build: unsafe-perm in lifecycle true
8 verbose lifecycle lulo@0.1.0~build: PATH: /Users/x/.nvm/versions/node/v10.0.0/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/x/Lulo/lulo/node_modules/.bin:/Users/x/.nvm/versions/node/v10.0.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
9 verbose lifecycle lulo@0.1.0~build: CWD: /Users/x/Lulo/lulo
10 silly lifecycle lulo@0.1.0~build: Args: [ '-c', 'react-scripts-ts build' ]
11 silly lifecycle lulo@0.1.0~build: Returned: code: 1  signal: null
12 info lifecycle lulo@0.1.0~build: Failed to exec build script
13 verbose stack Error: lulo@0.1.0 build: `react-scripts-ts build`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/Users/x/.nvm/versions/node/v10.0.0/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:285:16)
13 verbose stack     at EventEmitter.emit (events.js:182:13)
13 verbose stack     at ChildProcess.<anonymous> (/Users/x/.nvm/versions/node/v10.0.0/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:182:13)
13 verbose stack     at maybeClose (internal/child_process.js:947:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:236:5)
14 verbose pkgid lulo@0.1.0
15 verbose cwd /Users/luisvalencia/Lulo/lulo
16 verbose Darwin 18.0.0
17 verbose argv "/Users/x/.nvm/versions/node/v10.0.0/bin/node" "/Users/x/.nvm/versions/node/v10.0.0/bin/npm" "run-script" "build"
18 verbose node v10.0.0
19 verbose npm  v5.6.0
20 error code ELIFECYCLE
21 error errno 1
22 error lulo@0.1.0 build: `react-scripts-ts build`
22 error Exit status 1
23 error Failed at the lulo@0.1.0 build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
2个回答

这个线程有答案:

https://github.com/facebook/create-react-app/issues/4076

基本上,删除 node_modules 并从 package.json 依赖项中删除 webpack,然后npm install. 有些人通过使用yarn而不是npm来解决。

一段时间以来,我也一直在努力解决这个错误。我的问题是由于传递依赖。虽然在我的项目 package.json 中没有明确提到“webpack”作为依赖项,但我在 package-lock.json 中发现了 2 个版本的“webpack”。一个由“react-scripts”使用,另一个由“react-nbsp”使用,我在 package.json 中提到它作为依赖项,并使用它在 React JSX 中获得不间断的空间。

我从 package.json 中删除了“react-nbsp”,删除了节点module、package-lock.json 并运行了该应用程序。它开始没有错误并且工作正常。