upstash / qstash-js

Message queue for serverless
https://docs.upstash.com/qstash
MIT License
133 stars 11 forks source link

crypto is not defined #84

Closed camsloanftc closed 1 month ago

camsloanftc commented 3 months ago

I was trying to do the following:

import { Client } from "@upstash/qstash";

which led to the following build errors:

@hop/nextjs:build: 
@hop/nextjs:build: > Build error occurred
@hop/nextjs:build: ReferenceError: crypto is not defined
@hop/nextjs:build:     at file:///vercel/path0/packages/qstash-watcher/dist/updateQstashEndpoints-402ed4a3.mjs:31:11
@hop/nextjs:build:     at ModuleJob.run (node:internal/modules/esm/module_job:195:25)
@hop/nextjs:build:     at async ModuleLoader.import (node:internal/modules/esm/loader:336:24)
@hop/nextjs:build:     at async importModuleDynamicallyWrapper (node:internal/vm/module:429:15)
@hop/nextjs:build:     at async Object.loadConfig [as default] (/vercel/path0/node_modules/next/dist/server/config.js:78:36)
@hop/nextjs:build:     at async Span.traceAsyncFn (/vercel/path0/node_modules/next/dist/trace/trace.js:79:20)
@hop/nextjs:build:     at async /vercel/path0/node_modules/next/dist/build/index.js:78:28
@hop/nextjs:build:     at async Span.traceAsyncFn (/vercel/path0/node_modules/next/dist/trace/trace.js:79:20)
@hop/nextjs:build:     at async Object.build [as default] (/vercel/path0/node_modules/next/dist/build/index.js:73:29)
@hop/nextjs:build:  ELIFECYCLE  Command failed with exit code 1.
@hop/nextjs:build: ERROR: command finished with error: command (/vercel/path0/apps/nextjs) pnpm run build exited (1)
command (/vercel/path0/apps/nextjs) pnpm run build exited (1)

Somehow I was able to fix by importing directly from the dist folder:

import { Client } from "@upstash/qstash/dist";

Anyways, not sure if it's an mjs issue, or something with nextjs, or what, but figured I would add an issue to document, and let people know how I fixed it in case it helps someone else.

ogzhanolguncu commented 2 months ago

In docs or examples we generally recommend importing like this

import { Client } from "@upstash/qstash/dist"

But, we plan to fix this import issue and prevent those mistakes in the near future.

ogzhanolguncu commented 1 month ago

Imports no longer require /dist you can directly import @upstash/qstash.