Coder Social home page Coder Social logo

Comments (9)

tsndr avatar tsndr commented on September 4, 2024 3

I'm looking into this, sorry for the inconvenience.

from cloudflare-worker-jwt.

tsndr avatar tsndr commented on September 4, 2024 3

Hey guys, I've now added esbuild and released the change with v2.4.6, this should hopefully fix this issue.

@vnphanquang I really appreciate your effort with the PR (#67), but I've just switched over from js to ts a little while ago and would like to keep it that way. I think a bundler is the best way forward for now, but I'm also always open for feedback and suggestions :)

from cloudflare-worker-jwt.

vnphanquang avatar vnphanquang commented on September 4, 2024 1

@tsndr thank you. No worries I understand 😀

from cloudflare-worker-jwt.

vnphanquang avatar vnphanquang commented on September 4, 2024

This started in 2.4.1 when src/utils.ts was introduced. The problem is that tsc outputs the import statement for utils module as:

// index.js
import { ... } from "./utils";

This is incompatible with Node's ESM algorithm, which requires explicit .js extension. A possible fix is to include .js in src/index.ts

// src/index.ts
import { ... } from "./utils.js"

tsc will keep .js in output. However, test cases will fail because jest throws a Cannot find module './utils.js' from 'src/index.ts' error.

Hopefully these info are helpful. I will keep experimenting when i have some more time.


For the record, I'm using [email protected], [email protected], and @sveltejs/[email protected], with ESM syntax.

from cloudflare-worker-jwt.

tsndr avatar tsndr commented on September 4, 2024

Hey guys, I've created a test project, but for me everything is working as expected:

https://github.com/tsndr/cloudflare-worker-jwt-test

from cloudflare-worker-jwt.

focus-at avatar focus-at commented on September 4, 2024

same, trying on localhost in nuxt: 3.4.3 project

Cannot find module '.../@tsndr/cloudflare-worker-jwt/utils' imported from .../@tsndr/cloudflare-worker-jwt/index.js

from cloudflare-worker-jwt.

vnphanquang avatar vnphanquang commented on September 4, 2024

@tsndr yeah, a bundler is smart enough to resolve it without problem. esbuild is used in the case of wrangler. The reported issue only happens when running with bare node.

Now I understand this is a bit unexpected because the package is targeted at cloudflare environment and not node. But in the context of some frameworks (sveltekit for me and nuxt for @focus-at, which build apps to compatible output for cloudflare), seems like sometimes the modules are evaluated with node at build time. I am not sure if this is really necessary and should or should not be fixed from the framework side, but having the package compatible with Node's ESM algorithm would definitely be convenient.

I created this repo that reproduces the issue, please see README for the steps.

Here is the full log:

node:internal/modules/esm/resolve:264
    throw new ERR_MODULE_NOT_FOUND(
          ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/[...]/cloudflare-worker-jwt-esm-reproduction/node_modules/@tsndr/cloudflare-worker-jwt/utils' imported from /[...]/cloudflare-worker-jwt-esm-reproduction/node_modules/@tsndr/cloudflare-worker-jwt/index.js
    at finalizeResolution (node:internal/modules/esm/resolve:264:11)
    at moduleResolve (node:internal/modules/esm/resolve:917:10)
    at defaultResolve (node:internal/modules/esm/resolve:1130:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:396:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:365:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:240:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:85:39)
    at link (node:internal/modules/esm/module_job:84:36) {
  code: 'ERR_MODULE_NOT_FOUND',
  url: 'file:///[...]/cloudflare-worker-jwt-esm-reproduction/node_modules/@tsndr/cloudflare-worker-jwt/utils'
}

Node.js v20.11.0

from cloudflare-worker-jwt.

Eusebiotrigo avatar Eusebiotrigo commented on September 4, 2024

It is happening to us also when running tests in vitest.

Running workers with wrangler 3.28.4 (latest at this moment).
Running Node20.

from cloudflare-worker-jwt.

Eusebiotrigo avatar Eusebiotrigo commented on September 4, 2024

Thank you very much!!!

from cloudflare-worker-jwt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.