首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >模块未找到:错误:无法解析C:\中的“密码”

模块未找到:错误:无法解析C:\中的“密码”
EN

Stack Overflow用户
提问于 2022-01-23 07:42:53
回答 1查看 6.5K关注 0票数 2

错误消息:

代码语言:javascript
运行
复制
Compiled with problems:X

ERROR in ./node_modules/@solana/spl-name-service/dist/utils.js 16:17-34

Module not found: Error: Can't resolve 'crypto' in 'C:\Users\...\node_modules\@solana\spl-name-service\dist'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
    - add a fallback 'resolve.fallback: { "crypto": require.resolve("crypto-browserify") }'
    - install 'crypto-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
    resolve.fallback: { "crypto": false }

问题开始的

我尝试使用https://github.com/NftEyez/sol-rayz

  • Then,() from:
  • I得到了以下错误消息.

我的项目:

使用的

  • getParsedNftAccountsByOwner()
  • React,打字本project
  • Libraries:@solana/web3.js @nfteyez/sol-rayz
  • webpack 5.67.0

尽管我能够在几分钟内解决这些错误,但“密码”中的一个是不同的:

流问题:

代码语言:javascript
运行
复制
ERROR in ./node_modules/cipher-base/index.js 3:16-43

Module not found: Error: Can't resolve 'stream' in 'C:\Users\...\node_modules\cipher-base'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
    - add a fallback 'resolve.fallback: { "stream": require.resolve("stream-browserify") }'
    - install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
    resolve.fallback: { "stream": false }

断言问题:

代码语言:javascript
运行
复制
ERROR in ./node_modules/@solana/spl-name-service/dist/utils.js 14:33-50

Module not found: Error: Can't resolve 'assert' in 'C:\Users\...\node_modules\@solana\spl-name-service\dist'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
    - add a fallback 'resolve.fallback: { "assert": require.resolve("assert/") }'
    - install 'assert'
If you don't want to include a polyfill, you can use an empty module like this:
    resolve.fallback: { "assert": false }

到目前为止我所做的:

  1. 我尝试执行错误消息中的两项建议,但没有运行

  1. 我已经尝试了前两种解决方案:

"compilerOptions":{ "baseUrl":"./",“路径”:{ "crypto":“节点_模块/密码-js”}

Module not found: Error: Can't resolve 'crypto'

  1. --我尝试了这个解决方案:

“浏览器”:{“密码”:false }

https://github.com/tensorflow/tfjs/issues/494#issuecomment-481636128

我尝试了这个解决方案: node-polyfill-webpack-plugin

https://stackoverflow.com/a/65556946/18007508

代码语言:javascript
运行
复制
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin")
module.exports = {
        // Other rules...
        plugins: [
            new NodePolyfillPlugin()
        ]
    } 

My Code: webpack.config.js

代码语言:javascript
运行
复制
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin")
module.exports = {
  entry: "./src/components/index.tsx",
  target: "web",
  mode: "development",
  output: {
    path: path.resolve(\__dirname, "build"),
    filename: "bundle.js",
  },
  resolve: {
    extensions: [".js", ".jsx", ".json", ".ts", ".tsx"],
    fallback: {
      "crypto":require.resolve('crypto-browserify') ,
    } 
  },
  module: {
    rules: [
      {
        test: /\.(ts|tsx)$/,
        loader: "awesome-typescript-loader",
      },
      {
        enforce: "pre",
        test: /\.js$/,
        loader: "source-map-loader",
      },
      {
        test: /\.css$/,
        loader: "css-loader",
      },
    ],
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: path.resolve(\__dirname, "src", "components", "index.html"),
    }),
    new MiniCssExtractPlugin({
      filename: "./src/yourfile.css",
    }),
    new NodePolyfillPlugin()
  ],
};

package.json

代码语言:javascript
运行
复制
{
  "name": "my-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@headlessui/react": "^1.4.3",
    "@heroicons/react": "^1.0.5",
    "@nfteyez/sol-rayz": "^0.9.1",
    "@nfteyez/sol-rayz-react": "^0.9.1",
    "@solana/spl-name-service": "^0.1.3",
    "@solana/wallet-adapter-base": "^0.9.2",
    "@solana/wallet-adapter-react": "^0.15.2",
    "@solana/wallet-adapter-react-ui": "^0.9.4",
    "@solana/wallet-adapter-wallets": "^0.14.2",
    "@solana/web3.js": "^1.32.0",
    "@testing-library/jest-dom": "^5.16.1",
    "@testing-library/react": "^12.1.2",
    "@testing-library/user-event": "^13.5.0",
    "@types/jest": "^27.4.0",
    "@types/node": "^16.11.19",
    "assert": "^2.0.0",
    "axios": "^0.25.0",
    "browser": "^0.2.6",
    "crypto": "^1.0.1",
    "crypto-browserify": "^3.12.0",
    "crypto-js": "^4.1.1",
    "install": "^0.13.0",
    "node-polyfill-webpack-plugin": "^1.1.4",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-redux": "^7.2.6",
    "react-router": "^6.2.1",
    "react-router-dom": "^6.2.1",
    "react-scripts": "5.0.0",
    "redux": "^4.1.2",
    "redux-thunk": "^2.4.1",
    "store": "^2.0.12",
    "stream": "^0.0.2",
    "stream-browserify": "^3.0.0",
    "styled-components": "^5.3.3",
    "three": "^0.136.0",
    "web-vitals": "^2.1.3"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts 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"
    ]
  },
  "devDependencies": {
    "@types/react": "^17.0.38",
    "@types/react-dom": "^17.0.11",
    "@types/react-redux": "^7.1.22",
    "@types/react-router-dom": "^5.3.2",
    "@types/styled-components": "^5.1.20",
    "autoprefixer": "^10.4.2",
    "awesome-typescript-loader": "^5.2.1",
    "css-loader": "^6.5.1",
    "html-webpack-plugin": "^5.5.0",
    "mini-css-extract-plugin": "^2.5.0",
    "postcss": "^8.4.5",
    "source-map-loader": "^3.0.1",
    "tailwindcss": "^3.0.15",
    "typescript": "^4.5.4",
    "webpack-dev-server": "^4.7.3"
  }
}
EN

回答 1

Stack Overflow用户

发布于 2022-01-23 09:10:59

我认为这是因为您的create (CRA)不承认您的webpack.config.js。您的聚合填充设置是正确的。设置node-polyfill-webpack-plugin本身就足以加载所有节点核心填充。

为了修改CRA中的webpack.config.js,您必须运行

代码语言:javascript
运行
复制
   npm run eject

这将创建一个config目录,在您的内部将有将近1000行代码的webpack.config.js。在该文件中,设置node-polyfill-webpack-plugin就足够了。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70820082

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档