简体   繁体   English

(Create-React-App)找不到模块:您试图导入项目之外的 /node_modules/console-browserify/index.js

[英](Create-React-App) Module not found: You attempted to import /node_modules/console-browserify/index.js which falls outside of the project

Recently upgraded to version 5.0.1 of react-scripts and in doing that I needed to re-add support for Node.js core modules by importing NodePolyfillPlugin into my react-scripts config and adding it to plugins.最近升级到 react-scripts 的 5.0.1 版本,为此我需要通过将NodePolyfillPlugin导入我的 react-scripts 配置并将其添加到插件来重新添加对 Node.js 核心模块的支持。 That did resolve the errors I was seeing but now I'm getting some new errors when trying to npm start :这确实解决了我看到的错误,但现在我在尝试npm start时遇到了一些新错误:

Module not found: Error: You attempted to import /node_modules/console-browserify/index.js which falls outside of the project directory.

在此处输入图像描述 The only reference to console-browserify is coming from the NodePolyfillPlugin.对控制台浏览器的唯一引用来自 NodePolyfillPlugin。 Does anyone know why this happening and how I'd fix it?有谁知道为什么会发生这种情况以及我将如何解决它?

I ended up resolving this by adding the following when initiating NodePolyfillPlugin .我最终通过在启动NodePolyfillPlugin时添加以下内容来解决这个问题。 If you need to use console I would imagine this wouldn't work:如果您需要使用console ,我想这是行不通的:

new NodePolyfillPlugin({
  excludeAliases: ['console'],
});

暂无
暂无

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

相关问题 您试图导入位于项目 src/ 目录之外的.../node_modules/console-browserify/index.js - You attempted to import .../node_modules/console-browserify/index.js which falls outside of the project src/ directory React JS导入错误-找不到模块:您试图导入不在项目src /目录下的../actions - React JS import error - Module not found: You attempted to import ../actions which falls outside of the project src/ directory 我该如何解决此错误:找不到模块:您试图导入../../../view/file_upload 项目 src/ 目录之外 - how do i resolve this error: Module not found: You attempted to import ../../../view/file_upload which falls outside of the project src/ directory 必须使用 import 来加载 ES 模块: ...\node_modules\got\dist\source\index.js - Must use import to load ES module: ...\node_modules\got\dist\source\index.js 模块构建失败(来自./node_modules/react-scripts/node_modules/babel-loader/lib/index.js) - Module build failed (from ./node_modules/react-scripts/node_modules/babel-loader/lib/index.js) 反应构建错误:模块构建失败(来自 ./node_modules/babel-loader/lib/index.js): - React build error: Module build failed (from ./node_modules/babel-loader/lib/index.js): 启动 adonis 时出错 - 错误:找不到模块 '/app/node_modules/@poppinss/file-generator/index.js' - Error when start adonis - Error: Cannot find module '/app/node_modules/@poppinss/file-generator/index.js' 模块构建失败(来自 ./node_modules/babel-loader/lib/index.js)Vue Js - Module build failed (from ./node_modules/babel-loader/lib/index.js) Vue Js 模块构建失败(来自./node_modules/postcss-loader/src/index.js) - Module build failed (from ./node_modules/postcss-loader/src/index.js) 无法在Google Cloud Function中加载node_modules(index.js,不在项目根目录中) - Failed to loading node_modules in Google Cloud Function (index.js, not on the project root)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM