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

Build Error with ^1.24.0 (SvelteKit, Lucia-Auth and Cloudflare Pages) #698

Closed
polaroidkidd opened this issue Oct 28, 2023 · 5 comments · Fixed by #716
Closed

Build Error with ^1.24.0 (SvelteKit, Lucia-Auth and Cloudflare Pages) #698

polaroidkidd opened this issue Oct 28, 2023 · 5 comments · Fixed by #716

Comments

@polaroidkidd
Copy link

Hi Guys

Just wanted to let you know that there might be a regression bug breaking some builds when trying to use the cloudflare redis client on a sveltekit project. You can reproduce it by checking out this commit: https://github.com/polaroidkidd/cloudkit/tree/28db400e4ce687045d3123c77288d0b2e2745fb6

Update the @upstash/redis verison to 1.24.0 and then try running the pnpm preview:cf It should produce the below error

vite v4.5.0 building SSR bundle for production...
✓ 226 modules transformed.

node:internal/event_target:1083
  process.nextTick(() => { throw err; });
                           ^
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '[PATH-TO-PROJECT]/cloudkit/node_modules/.pnpm/@upstash+redis@1.24.1/node_modules/crypto-js/enc-hex' imported from [PATH-TO-PROJECT]/cloudkit/node_modules/.pnpm/@upstash+redis@1.24.1/node_modules/@upstash/redis/cloudflare.mjs
Did you mean to import crypto-js@4.2.0/node_modules/crypto-js/enc-hex.js?
    at new NodeError (node:internal/errors:406:5)
    at finalizeResolution (node:internal/modules/esm/resolve:233:11)
    at moduleResolve (node:internal/modules/esm/resolve:845:10)
    at defaultResolve (node:internal/modules/esm/resolve:1043:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:383:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:352:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:228:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:85:39)
    at link (node:internal/modules/esm/module_job:84:36)
Emitted 'error' event on Worker instance at:
    at [kOnErrorMessage] (node:internal/worker:326:10)
    at [kOnMessage] (node:internal/worker:337:37)
    at MessagePort.<anonymous> (node:internal/worker:232:57)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:807:20)
    at exports.emitMessage (node:internal/per_context/messageport:23:28) {
  url: 'file://[PATH-TO-PROJECT]/cloudkit/node_modules/.pnpm/@upstash+redis@1.24.1/node_modules/crypto-js/enc-hex',
  code: 'ERR_MODULE_NOT_FOUND'
}
@ogzhanolguncu
Copy link
Collaborator

Thanks for letting us know. I'll start working on it.

@chronark
Copy link
Contributor

chronark commented Oct 31, 2023

Hey, we are running tests against cloudflare workers in the CI and that works, so I'm a bit confused about it.
Could this be related to using sveltekit?

Either way, could you try and do what the error suggests and report back if it solves it?

npm i crypto-js

@polaroidkidd
Copy link
Author

Hi,

I'm still getting the error. You can check out this PR to reproduce the error. The build job fails with the same error.

You can reproduce it locally by following these steps

  1. Clone that branch
  2. run pnpm install
  3. copy .env.example to .env.production
  4. run pnpm prisma:gen:prod
  5. run pnpm build:prod

It cloud be due to using SvelteKit. SvelteKit uses vite to run it the build and then the sveltekit cloudflare plugin handles the transformation of the vite build to something wrangler can work with. The error seems to be happening while vite attempts to bundle the app.

I've copy&pasted the build-output below. I'm on a Linux system.

node:internal/event_target:1083
  process.nextTick(() => { throw err; });
                           ^
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/dle/DevWork/me/cloudkit/node_modules/.pnpm/@upstash+redis@1.24.3/node_modules/crypto-js/enc-hex' imported from /home/dle/DevWork/me/cloudkit/node_modules/.pnpm/@upstash+redis@1.24.3/node_modules/@upstash/redis/chunk-KBK5EDMP.mjs
Did you mean to import crypto-js@4.2.0/node_modules/crypto-js/enc-hex.js?
    at new NodeError (node:internal/errors:406:5)
    at finalizeResolution (node:internal/modules/esm/resolve:233:11)
    at moduleResolve (node:internal/modules/esm/resolve:845:10)
    at defaultResolve (node:internal/modules/esm/resolve:1043:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:383:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:352:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:228:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:85:39)
    at link (node:internal/modules/esm/module_job:84:36)
Emitted 'error' event on Worker instance at:
    at [kOnErrorMessage] (node:internal/worker:326:10)
    at [kOnMessage] (node:internal/worker:337:37)
    at MessagePort.<anonymous> (node:internal/worker:232:57)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:807:20)
    at exports.emitMessage (node:internal/per_context/messageport:23:28) {
  url: 'file:///home/dle/DevWork/me/cloudkit/node_modules/.pnpm/@upstash+redis@1.24.3/node_modules/crypto-js/enc-hex',
  code: 'ERR_MODULE_NOT_FOUND'
}

Node.js v20.9.0
 ELIFECYCLE  Command failed with exit code 1.
}

Node.js v20.9.0
 ELIFECYCLE  Command failed with exit code 1.
 ```

@ogzhanolguncu
Copy link
Collaborator

I tested with this CF Example and it worked. Looks like it's not working when paired with cf pages. I'll check again. We might have to use opt out of crypto-js when redis/cloudflare used.

@yutak23
Copy link
Contributor

yutak23 commented Nov 9, 2023

The same error occurred when building with SveltKit using @sveltejs/adapter-cloudflare.

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/study/workspace/cat-faq-bot/node_modules/crypto-js/enc-hex' imported from /home/study/workspace/cat-faq-bot/node_modules/@upstash/redis/chunk-KBK5EDMP.mjs
Did you mean to import crypto-js/enc-hex.js?
    at new NodeError (node:internal/errors:405:5)
    at finalizeResolution (node:internal/modules/esm/resolve:324:11)
    at moduleResolve (node:internal/modules/esm/resolve:943:10)
    at defaultResolve (node:internal/modules/esm/resolve:1129:11)
    at nextResolve (node:internal/modules/esm/loader:163:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:835:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:77:40)
    at link (node:internal/modules/esm/module_job:76:36)
Emitted 'error' event on Worker instance at:
    at [kOnErrorMessage] (node:internal/worker:300:10)
    at [kOnMessage] (node:internal/worker:311:37)
    at MessagePort.<anonymous> (node:internal/worker:212:57)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:741:20)
    at exports.emitMessage (node:internal/per_context/messageport:23:28) {
  code: 'ERR_MODULE_NOT_FOUND'
}

image

The "moduleResolution": "bundler", allows the extension to be omitted, but I do not think it is currently possible to omit the extension in all cases. In fact, when building SveltKit @sveltejs/adapter-cloudflare, an error occurred when building it as an ES Module because it did not have a file extension.

environment

  • "@upstash/redis": "^1.24.3"
  • "svelte": "^4.2.2"
  • "@sveltejs/kit": "^1.27.1"
  • "@sveltejs/adapter-cloudflare": "^2.3.3"
  • Node.js v18.17.0

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

Successfully merging a pull request may close this issue.

4 participants