React.js收到“找不到模块loadash.template”错误

时间:2020-10-28 16:57:54

标签: reactjs

我使用npx create-react-app myapp创建了一个react应用,并在运行npm start时遇到以下错误

Error: Cannot find module 'lodash.template'

Require stack:

- C:\Desktop\react\myapp\node_modules\workbox-build\build\lib\populate-sw-template.js

- C:\Desktop\react\myapp\node_modules\workbox-webpack-plugin\build\generate-sw.js

- C:\Desktop\react\myapp\node_modules\workbox-webpack-plugin\build\index.js

- C:\\Desktop\react\myapp\node_modules\react-scripts\config\webpack.config.js

- C:\Desktop\react\myapp\node_modules\react-scripts\scripts\start.js

    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)

    at Function.Module._load (internal/modules/cjs/loader.js:725:27)

    at Module.require (internal/modules/cjs/loader.js:952:19)

    at require (internal/modules/cjs/helpers.js:88:18)

    at Object.<anonymous> (C:\Users\vanst\OneDrive\Desktop\react\myapp\node_modules\workbox-build\build\lib\populate-sw-template.js:10:18)

    at Module._compile (internal/modules/cjs/loader.js:1063:30)

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)

    at Module.load (internal/modules/cjs/loader.js:928:32)

    at Function.Module._load (internal/modules/cjs/loader.js:769:14)

    at Module.require (internal/modules/cjs/loader.js:952:19) {

  code: 'MODULE_NOT_FOUND',

}

npm ERR! code ELIFECYCLE

npm ERR! errno 1

npm ERR! myapp@0.1.0 start: `react-scripts start`

npm ERR! Exit status 1

npm ERR!

npm ERR! Failed at the myapp@0.1.0 start 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!     C:\Users\AppData\Roaming\npm-cache\_logs\2020-10-28T16_45_32_029Z-debug.log

我可以通过运行npm install loadash --save来解决此问题,但是如果不这样做,我在网上找到的说明似乎可以正常工作。我重新安装了node.js,此错误再次弹出,我想知道出了什么问题。

1 个答案:

答案 0 :(得分:1)

尝试清除缓存:

npm cache clear --force