Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find module './src/cipherSuite.js' #302

Open
OR13 opened this issue Feb 24, 2024 · 5 comments
Open

Cannot find module './src/cipherSuite.js' #302

OR13 opened this issue Feb 24, 2024 · 5 comments

Comments

@OR13
Copy link
Contributor

OR13 commented Feb 24, 2024

_sync:2 Uncaught Error: Cannot find module './src/cipherSuite.js'
    at webpackEmptyContext (_sync:2:10)
    at eval (mod.js:30:28)
    at eval (mod.js:17:17)
    at eval (mod.js:26:3)
    at ./node_modules/hpke-js/script/mod.js (main.js:372:1)
    at __webpack_require__ (main.js:726:42)
    at eval (app.js:40:17)
    at ./app.js (main.js:19:1)
    at __webpack_require__ (main.js:726:42)
    at eval (index.js:2:62)

This error occurs when bundling with web pack, a typescript application, that included hpke-js.

I created a PoC here: #301

@dajiaji
Copy link
Owner

dajiaji commented Feb 24, 2024

Thanks for the report. I'll check tomorrow.

@OR13
Copy link
Contributor Author

OR13 commented Feb 24, 2024

If I figure it out before then, I will update the PR and mark it "not draft", with some comments.

@OR13
Copy link
Contributor Author

OR13 commented Feb 24, 2024

Please don't let my comments here keep you awake.

Interestingly switching from:

import { AeadId, CipherSuite, KdfId, KemId } from "hpke-js";
import { AeadId, CipherSuite, KdfId, KemId } from "@hpke/core";

causes a different error:

of the same form:

Uncaught Error: Cannot find module '../src/aeads/aesGcm.js'

Seems to be the first "none type" export here:

https://github.com/dajiaji/hpke-js/blob/main/core/mod.ts#L16

Screenshot 2024-02-24 at 8 58 17 AM

Seems like webpack needs to be instructed to use node modules resolve relative paths in dependencies properly

Possibly relevant: webpack/webpack#472

This worked:

const path = require('path');
module.exports = [{
  mode: 'development',
  entry: './index.js',
  watch: true,
  plugins: [],
  resolve: {
    alias: {
      '@hpke/core': path.resolve('./node_modules/@hpke/core')
    },
    fallback: { 
      "crypto": false
    }
 }
}];

@dajiaji
Copy link
Owner

dajiaji commented Feb 25, 2024

Please don't let my comments here keep you awake.

Don't worry. I fell asleep before I saw your comment above :-)
I'll now check your PR.

@OR13
Copy link
Contributor Author

OR13 commented Feb 25, 2024

For those trying to use this library in next 14 or greater:

You can update webpack used by next, like this:

https://nextjs.org/docs/app/api-reference/next-config-js/webpack

const path = require("path");

module.exports = {
  webpack: (
    config,
    { buildId, dev, isServer, defaultLoaders, nextRuntime, webpack }
  ) => {
    // Important: return the modified config
    return {
      ...config, 
      resolve: {
        ...config.resolve,
        alias: {
          ...config.resolve.alias,
          "hpke-js": path.resolve("./node_modules/hpke-js"),
        },
        fallback: {
          ...config.resolve.fallback,
          "crypto": false,
        },
      },
    }
  },
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants