我有一个我已经在Heroku上部署的React.js应用程序。然后我收到此消息:
浏览器列表:caniuse-lite已过时。请运行下一个命令
npm update
。
因此,我运行npm update
和npm audit fix
。再次推到Heroku时,出现此错误:
错误:找不到模块'react-dev-utils / getPublicUrlOrPath'
这是我在运行git push heroku master
时得到的:
remote: -----> Buildremote: Running build
remote:
remote: > products-management@0.1.0 build /tmp/build_3b9104b8c72e292510eb4a5bd0494704
remote: > react-scripts build
remote:
remote: internal/modules/cjs/loader.js:960
remote: throw err;
remote: ^
remote:
remote: Error: Cannot find module 'react-dev-utils/getPublicUrlOrPath'
remote: Require stack:
remote: - /tmp/build_3b9104b8c72e292510eb4a5bd0494704/node_modules/react-scripts/config/paths.js
remote: - /tmp/build_3b9104b8c72e292510eb4a5bd0494704/node_modules/react-scripts/config/env.js
remote: - /tmp/build_3b9104b8c72e292510eb4a5bd0494704/node_modules/react-scripts/scripts/build.js
remote: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:957:15)
remote: at Function.Module._load (internal/modules/cjs/loader.js:840:27)
remote: at Module.require (internal/modules/cjs/loader.js:1019:19)
remote: at require (internal/modules/cjs/helpers.js:77:18)
remote: at Object.<anonymous> (/tmp/build_3b9104b8c72e292510eb4a5bd0494704/node_modules/react-scripts/config/paths.js:13:28)
remote: at Module._compile (internal/modules/cjs/loader.js:1133:30)
remote: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
remote: at Module.load (internal/modules/cjs/loader.js:977:32)
remote: at Function.Module._load (internal/modules/cjs/loader.js:877:14)
remote: at Module.require (internal/modules/cjs/loader.js:1019:19) {
remote: code: 'MODULE_NOT_FOUND',
remote: requireStack: [
remote: '/tmp/build_3b9104b8c72e292510eb4a5bd0494704/node_modules/react-scripts/config/paths.js',
remote: '/tmp/build_3b9104b8c72e292510eb4a5bd0494704/node_modules/react-scripts/config/env.js',
remote: '/tmp/build_3b9104b8c72e292510eb4a5bd0494704/node_modules/react-scripts/scripts/build.js'
remote: ]
remote: }
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 1
remote: npm ERR! products-management@0.1.0 build: `react-scripts build`
remote: npm ERR! Exit status 1
remote: npm ERR!
remote: npm ERR! Failed at the products-management@0.1.0 build script.
remote: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR! /tmp/npmcache.qnMyP/_logs/2020-05-07T07_23_33_937Z-debug.log
remote:
remote: -----> Build failed
remote:
remote: We're sorry this build is failing! You can troubleshoot common issues here:
remote: https://devcenter.heroku.com/articles/troubleshooting-node-deploys
remote:
remote: Some possible problems:
remote:
remote: - node_modules checked into source control
remote: https://blog.heroku.com/node-habits-2016#9-only-git-the-important-bits
remote:
remote: - Node version not specified in package.json
remote: https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
remote:
remote: Love,
remote: Heroku
remote: ! Push rejected, failed to compile Node.js app.
remote: ! Push failed`enter code here`
答案 0 :(得分:1)
虽然不在Heroku上,但我也遇到了类似的问题,但有同样的getPublicUrlOrPath
错误。我尝试了npm-install多次,并从一个错误的依赖项中得到了404错误,所以我从package.json中删除了它,删除了package-lock.json文件,然后运行npm install --save
,然后一切正常。>
答案 1 :(得分:0)
尝试使用
npm install --save-dev react-dev-utils
每次都对我有用