简体   繁体   English

您试图导入位于项目 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

I keep getting the below error when trying to build on AWS Amplify.尝试在 AWS Amplify 上构建时,我不断收到以下错误。 I don't really understand the error as the node_modules packages should be built by Amplify.我不太明白这个错误,因为 node_modules 包应该由 Amplify 构建。 (Or course it's outside the src directory - it's a Node package (或者当然它在 src 目录之外 - 它是一个节点 package

Is there a solution to this?有针对这个的解决方法吗?

2022-07-15T12:18:10.405Z [INFO]: Failed to compile.
2022-07-15T12:18:10.411Z [INFO]: Module not found: Error: You attempted to import /codebuild/output/src341411582/src/react-sol/node_modules/console-browserify/index.js which falls outside of the project src/ directory. Relative imports outside of src/ are not supported.
                                 You can either move it inside src/, or add a symlink to it from project's node_modules/.

This is my webpack.config.js这是我的 webpack.config.js

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

module.exports = {
  plugins: {
    add: [
      new webpack.ProvidePlugin({
        process: "process/browser.js",
      }),
      new NodePolyfillPlugin({
        excludeAliases: ['console-browserify'], //have tried with and without this
      }),
    ],
  },
  node: {
    fs: "empty",
  },
};

package.json (I've listed everything) package.json(我已经列出了所有内容)

{
  "name": "mb-react",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@chakra-ui/react": "^2.2.1",
    "@emailjs/browser": "^3.6.2",
    "@emotion/react": "^11.9.3",
    "@emotion/styled": "^11.9.3",
    "@fontsource/akaya-telivigala": "^4.5.6",
    "@fontsource/cabin-sketch": "^4.5.7",
    "@fontsource/sora": "^4.5.8",
    "@metaplex-foundation/js": "^0.11.7",
    "@solana-mobile/wallet-adapter-mobile": "^0.0.1-alpha.1",
    "@solana/pay": "^0.2.0",
    "@solana/spl-token": "^0.2.0",
    "@solana/wallet-adapter-base": "^0.9.8",
    "@solana/wallet-adapter-react": "^0.15.7",
    "@solana/wallet-adapter-react-ui": "^0.9.9",
    "@solana/wallet-adapter-wallets": "^0.16.7",
    "@solana/web3.js": "^1.47.3",
    "@testing-library/jest-dom": "^5.16.4",
    "@testing-library/react": "^13.0.0",
    "@testing-library/user-event": "^14.0.0",
    "@toruslabs/openlogin": "^2.2.0",
    "@walletconnect/web3-provider": "^1.7.8",
    "@web3auth/web3auth": "^1.1.0",
    "antd": "^4.21.0",
    "aws-sdk": "^2.1170.0",
    "bignumber.js": "^9.0.2",
    "bootstrap": "^5.1.3",
    "ethereumjs-abi": "^0.6.8",
    "framer-motion": "4.1.17",
    "fs": "^0.0.1-security",
    "fs-webpack-plugin": "^3.1.3",
    "gsap": "^3.10.4",
    "jquery": "^3.6.0",
    "moralis": "^1.9.0",
    "node-polyfill-webpack-plugin": "^2.0.0",
    "react": "^18.2.0",
    "react-blockies": "^1.4.1",
    "react-bootstrap": "^2.4.0",
    "react-confetti": "^6.1.0",
    "react-dom": "^18.2.0",
    "react-moralis": "^1.4.0",
    "react-router-dom": "^6.3.0",
    "react-scripts": "^5.0.0",
    "react-spinners": "^0.12.0",
    "react-typewriter-effect": "^1.1.0",
    "react-use": "^17.4.0",
    "serve": "^13.0.2",
    "styled-components": "^5.3.5",
    "swiper": "^8.2.5",
    "typescript": "^4.7.3",
    "web-vitals": "^2.1.4",
    "web3uikit": "^0.1.166"
  },
  "scripts": {
    "start": "react-app-rewired start",
    "build": "react-app-rewired build",
    "test": "react-app-rewired test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version",
      "defaults"
    ]
  },
  "devDependencies": {
    "assert": "^2.0.0",
    "buffer": "^6.0.3",
    "crypto-browserify": "^3.12.0",
    "https-browserify": "^1.0.0",
    "os-browserify": "^0.3.0",
    "process": "^0.11.10",
    "react-app-rewired": "^2.2.1",
    "stream-browserify": "^3.0.0",
    "stream-http": "^3.2.0",
    "url": "^0.11.0"
  },
  "browser": {
    "fs": false,
    "path": false,
    "os": false
  }
}

Alias for console-browserify inside node-polyfill-webpack-plugin is console. node-polyfill-webpack-plugin 中的 console-browserify 的别名是 console。 Try this:尝试这个:

module.exports = {
  plugins: {
    add: [
      new webpack.ProvidePlugin({
        process: "process/browser.js",
      }),
      new NodePolyfillPlugin({
        excludeAliases: ['console'],
      }),
    ],
  },
  node: {
    fs: "empty",
  },
};

暂无
暂无

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

相关问题 (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 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 错误:ENOENT:没有那个文件或目录,打开 C:\\myangularproject\\src\\node_modules\\nlcst-pattern-match\\lib\\index.js - Error: ENOENT: no such file or directory, open C:\myangularproject\src\node_modules\nlcst-pattern-match\lib\index.js 模块构建失败(来自./node_modules/postcss-loader/src/index.js) - Module build failed (from ./node_modules/postcss-loader/src/index.js) 必须使用 import 来加载 ES 模块: ...\node_modules\got\dist\source\index.js - Must use import to load ES module: ...\node_modules\got\dist\source\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) 错误:“/my dir/node_modules/babel-preset-php/src/index.js”中指定的插件 0 提供了“默认”的无效属性 - Error: Plugin 0 specified in "/my dir/node_modules/babel-preset-php/src/index.js" provided an invalid property of "default" 模块构建失败(来自./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.js中通过index.js导入目录 - Directory import via index.js in Node.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM