简体   繁体   English

影响 vercel 部署但不影响本地构建的错误

[英]Error affecting vercel deployment but not a local build

I keep getting this error when compiling on Vercel or Heroku, but not on my PC.在 Vercel 或 Heroku 上编译时,我不断收到此错误,但在我的 PC 上却没有。

Module not found: Error: You attempted to import /vercel/path0/node_modules/console-browserify/index.js which falls outside of the project src/ directory. Relative imports outside of src/ are not supported.

This is an error I get when running npm run build on Vercel, it does not occur on a local build.这是我在 Vercel 上运行npm run build时遇到的错误,它不会发生在本地构建上。

I have tried changing the webpack version (it just gives a different error).我试过更改 webpack 版本(它只是给出了不同的错误)。 I have no idea where console-browserify is used (apart from react itself).我不知道在哪里使用 console-browserify(除了反应本身)。

I had the same problem deploying on Netlify.我在 Netlify 上部署时遇到了同样的问题。 I'm using https://github.com/Richienb/node-polyfill-webpack-plugin .我正在使用https://github.com/Richienb/node-polyfill-webpack-plugin

All I have to do is to exclude console-browsify我所要做的就是排除 console-browsify

const NodePolyfillPlugin = require("node-polyfill-webpack-plugin")

module.exports = {
    // Other rules...
    plugins: [
        new NodePolyfillPlugin({
            excludeAliases: ["console"]
        })
    ]
}

The problem was resolved by just removing all console.log , console.warn , etc. from the program!只需从程序中删除所有console.logconsole.warn等即可解决问题!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM