npm 安装Cardano-sdk/core时出现问题

vd8tlhqk  于 2023-10-19  发布在  其他
关注(0)|答案(1)|浏览(101)

我有一个Angular 的应用程序,并希望安装@cardano-sdk/core直接与Cardano工作,但在安装过程中,我得到这个错误,这似乎是在Cardano文件:

./node_modules/@dcspark/cardano-multiplatform-lib-nodejs/cardano_multiplatform_lib.js:35766:11-31 - Error: Module not found: Error: Can't resolve 'path' in '/Users/Lilit_Mazmanyan/WebstormProjects/tez-front/node_modules/@dcspark/cardano-multiplatform-lib-nodejs'

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: { "path": require.resolve("path-browserify") }'
        - install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "path": false }

下面是我的webpack.config.js:

const path = require('path');
const webpack = require('webpack');

module.exports = {
  mode: 'development', entry: './src/index.js', output: {
    filename: 'bundle.js', path: path.resolve(__dirname, 'dist'),
  }, resolve: {
    fallback: {
      'path': false
    }
  }
};

我也试过用"fs": false, "path": require.resolve("path-browserify"), "buffer": require.resolve("buffer/")代替路径,但也没有帮助。
下面是package.json:

{
  "name": "tez-front",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^14.2.0",
    "@angular/common": "^14.2.0",
    "@angular/compiler": "^14.2.0",
    "@angular/core": "^14.2.0",
    "@angular/forms": "^14.2.0",
    "@angular/platform-browser": "^14.2.0",
    "@angular/platform-browser-dynamic": "^14.2.0",
    "@angular/router": "^14.2.0",
    "@cardano-sdk/core": "^0.11.0",
    "@types/pouchdb-core": "^7.0.11",
    "pouchdb-core": "^8.0.1",
    "rxjs": "~7.5.0",
    "tslib": "^2.3.0",
    "util": "^0.12.5",
    "zone.js": "~0.11.4"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^14.2.11",
    "@angular/cli": "~14.2.11",
    "@angular/compiler-cli": "^14.2.0",
    "@types/blake2b": "^2.1.0",
    "@types/jasmine": "~4.0.0",
    "@types/lodash": "^4.14.194",
    "buffer": "^6.0.3",
    "jasmine-core": "~4.3.0",
    "karma": "~6.4.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.2.0",
    "karma-jasmine": "~5.1.0",
    "karma-jasmine-html-reporter": "~2.0.0",
    "path-browserify": "^1.0.1",
    "typescript": "~4.7.2"
  }
}

我看过similar issue,但它并没有帮助解决问题。
我该如何解决问题?

hfyxw5xn

hfyxw5xn1#

您可以尝试以下操作:
1.添加@dcspark/cardano-multiplatform-lib-browser作为依赖项。这就是你想要在浏览器中运行的风格。
1.更新webpack,将导入到“@dcspark/cardano-multiplatform-lib-nodejs”的内容替换为浏览器版本:

plugins: [
      new NormalModuleReplacementPlugin(
        /@dcspark\/cardano-multiplatform-lib-nodejs/,
        '@dcspark/cardano-multiplatform-lib-browser'
      ),
  • cardano-js-sdk web扩展e2 e测试是如何设置它的一个很好的资源。还有其他模块的更换和安装,你必须做。
  • 蕾丝钱包是另一个很好的例子,但由于它是一个产品,而不是一个e2 e测试,因此复杂性更高。

相关问题