Comments (9)
I'm looking into this, sorry for the inconvenience.
from cloudflare-worker-jwt.
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.
@tsndr thank you. No worries I understand 😀
from cloudflare-worker-jwt.
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.
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.
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.
@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.
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.
Thank you very much!!!
from cloudflare-worker-jwt.
Related Issues (20)
- HMAC "jwk" key import requires a JSON Web Key with Key Type parameter ("kty") equal to "oct" (encountered "RSA") HOT 3
- Verify always returns false. HOT 2
- Type definition does not allow for `kid`
- Allow passing CryptoKey directly
- Decoding the payload results in garbled text when the JWT contains non-ASCII characters
- JSON Web Key (JWK) not working with RS256 algorithm HOT 6
- JwtPayload is too lax
- Signing/Verifying an ES256 JWT fails HOT 3
- algo validation missing HOT 1
- Feature request - clockTolerance HOT 2
- verify function fail HOT 5
- Error: EXPIRED
- Not handling tokens correctly (or at least discrepant) HOT 2
- Full verification of Cloudflare Access token
- kid not passed
- Make verify to return the decoded token
- Why does this not work with normal nodejs? HOT 1
- [CF Pages Sveltkit Server-side] ReferenceError: CryptoKey is not defined
- `throwError` does not throw on invalid signature HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cloudflare-worker-jwt.