qstash-js icon indicating copy to clipboard operation
qstash-js copied to clipboard

crypto is not defined

Open camsloanftc opened this issue 1 year ago • 1 comments

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.

camsloanftc avatar Apr 04 '24 22:04 camsloanftc

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 avatar Apr 19 '24 07:04 ogzhanolguncu

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

ogzhanolguncu avatar May 16 '24 11:05 ogzhanolguncu