代码之家  ›  专栏  ›  技术社区  ›  marlonga

错误:在Ionic Angular应用程序中使用argon2浏览器时找不到模块

  •  0
  • marlonga  · 技术社区  · 3 年前

    我想在我的Ionic Angular项目中使用argon2浏览器。 一旦我与同步

    ionic cap sync
    

    我收到以下错误:

    ./node_modules/argon2-browser/dist/argon2.js:35:22-45 - Error: Module not found: Error: Can't resolve 'path' in 'C:\Users\SomeUser\WebstormProjects\foo\project\node_modules\argon2-browser\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: { "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 }
    
    ./node_modules/argon2-browser/dist/argon2.js:40:26-39 - Error: Module not found: Error: Can't resolve 'fs' in 'C:\Users\SomeUser\WebstormProjects\foo\project\node_modules\argon2-browser\dist'
    
    ./node_modules/argon2-browser/dist/argon2.wasm - Error: Module not found: Error: Can't resolve 'a' in 'C:\Users\SomeUser\WebstormProjects\foo\project\\node_modules\argon2-browser\dist'
    
    

    以下是相关代码:

    async generateHash() {
        const hash = await argon2.hash({pass: "testPassword", salt: "testSalt", type: 0})
          .then(h => console.log(h.hash, h.hashHex, h.encoded))
          .catch(e => console.error(e.message, e.code));
      }
    

    和我的包.json的剪辑:

    "dependencies": {
    ...
     "@angular/cdk": "^15.2.9",
     "@angular/common": "^15.0.0",
     "@angular/core": "^15.0.0",
     "@angular/forms": "^15.0.0",
     "@angular/platform-browser": "^15.0.0",
     "@angular/platform-browser-dynamic": "^15.0.0",
     "@types/argon2-browser": "^1.18.1",
    ...
    },
    "devDependencies": {
     "@angular/cli": "^15.0.0",
     "@angular/compiler": "^15.0.0",
     "@angular/compiler-cli": "^15.0.0",
     "@angular/language-service": "^15.0.0",
     "@capacitor/cli": "^4.7.0",
     "@ionic/angular-toolkit": "^8.0.0",
     "@ionic/cli": "^6.20.9",
     "argon2-browser": "^1.18.0",
    }
    
    

    我尝试过的:

    • 安装了找不到的模块

    • 将以下内容添加到我的package.json中:

     "browser":{
        "path": false,
        "fs": false,
        "a": false
      },
    

    这导致在同步项目时不会出现错误。但当我在android设备上运行代码时,我会收到以下错误:

    Msg: WebAssembly.instantiate(): Import #0 module="a" function="a" error: function import requires a callable undefined
    

    我做错了什么?

    感谢您提前提供的帮助:)

    0 回复  |  直到 3 年前