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

Module not found - Node version 14.15.1 #143

Closed
AlexandreB27 opened this issue Jan 13, 2021 · 5 comments
Closed

Module not found - Node version 14.15.1 #143

AlexandreB27 opened this issue Jan 13, 2021 · 5 comments
Labels
tooling issue A tooling issue outside of the library, e.g. transpilers, bundlers, etc not supporting exports yet

Comments

@AlexandreB27
Copy link

Hello

I want to use your library, especially jwt part of your library. But, when I import jose/jwr/sign with ESM import, I have an error on module not found :

Module not found: Error: Can't resolve 'jose/jwt/sign'

To Reproduce

I initialized an angular project and I ran npm install jose@3

Code to reproduce the behaviour:

import { Component } from '@angular/core';
import SignJWT from 'jose/jwt/sign'


@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'metabase';

  constructor() {
    this.test();
  }

  public async test() {
    const secretKey = ''';

    var string = btoa(unescape(encodeURIComponent(secretKey))),
      charList = string.split(''),
      uintArray = [];
    for (var i = 0; i < charList.length; i++) {
      uintArray.push(charList[i].charCodeAt(0));
    }
    var key = new Uint8Array(uintArray);
    const jwt = await new SignJWT({ 'urn:example:claim': true })
      .setProtectedHeader({ alg: 'ES256' })
      .setIssuedAt()
      .setIssuer('urn:example:issuer')
      .setAudience('urn:example:audience')
      .setExpirationTime('2h')
      .sign(key)

  }

}

Environment:

  • jose version: v3.5.1
  • affected runtime is: Node.js 14.15.1]

What I did wrong ?

@panva
Copy link
Owner

panva commented Jan 13, 2021

Whatever loader used by the stack you use to compile does not support subpath exports. This is not a bug in the library but a lack of node's module resolution support in your stack. You can resolve to directly import the specific dist file but it's not the regular way and you probably won't get types.

@panva panva closed this as completed Jan 13, 2021
@panva panva added tooling issue A tooling issue outside of the library, e.g. transpilers, bundlers, etc not supporting exports yet and removed triage labels Jan 13, 2021
@panva
Copy link
Owner

panva commented Jan 13, 2021

@AlexandreB27 I've published an experimental version hoping to somehow support these left behind runtimes and loaders.

npm install [email protected]

Instead of import SignJWT from 'jose/jwt/sign' do import { SignJWT } from 'jose'.

Please come back to me with details whether that worked for you and definitely more details on what you use to compile the code you've posted above.

@tmmschmit
Copy link

@panva, Hello sorry to resurrect an old issue, I had the same problem on a react app with the last version (3.11.1) but it's working well with [email protected] 🤔

@panva
Copy link
Owner

panva commented Mar 29, 2021

@tmmschmit I'm not going to be moving forward with a single root export module. Over time tooling ecosystems will pick up the Subpath Conditional schemes.

If your tooling doesn't support simply import SignJWT from 'jose/jwt/sign' then file an issue with said tooling for them to add this capability. Until then, you can find the actual dist file in your node modules and import from that as a workaround.

@LouisStAmour
Copy link

LouisStAmour commented Apr 11, 2021

For folks looking for TypeScript support of export mapping in package.json, it's supposed to be in the next TypeScript release, 4.3 but no code has appeared yet. The tracking issue for support is at microsoft/TypeScript#33079

For now, I'm doing things like the following:

// @ts-ignore
import { createRemoteJWKSet } from 'jose/jwks/remote';
// @ts-ignore
import { jwtVerify } from 'jose/jwt/verify';

Not great because of course, I don't get any type-checking. I've searched GitHub to see what others are doing and it looks like using ts-node instead of tsc directly is also an option, though I haven't tried it yet. One repo I saw actually copied all the types out of the module to add types that way, but that sounds like a pain. I had an idea that maybe I could make simple .d.ts files that referenced the existing types from the package, but even that seemed like too much work. I'll just wait for the next TS release in a month or two.

@github-actions github-actions bot locked and limited conversation to collaborators Jul 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
tooling issue A tooling issue outside of the library, e.g. transpilers, bundlers, etc not supporting exports yet
Projects
None yet
Development

No branches or pull requests

4 participants