nuxt-auth: CloudFlare Pages deployment fails with RollupError

Environment

  • Node Version v16.15.1 / v18.15.0
  • nuxt 3.4.3
  • Nitro 2.4.0
  • @sidebase/nuxt-auth 0.5.0 / 0.6.0-beta.0
  • next-auth 4.22.1

Reproduction

No response

Describe the bug

During the deployment process on CloudFlare Pages,an error is occurring because the jose package is unable to use the createHash function from the unenv package it depends on. Specifically, the digest.js file in the jose package is importing the createHash function from the crypto package, but it needs to retrieve createHash from the crypto module of the unenv package, which is not properly exported.

Additional context

I have tried the following and would like to report an issue:

  • Removing the nuxt-auth module from nuxt.config.ts allows the application to function correctly.
  • The issue occurs regardless of the version of nuxt-auth used.
  • The issue persists even when NODE_VERSION is changed between v14 and v19.
  • When using nitro.preset=‘node-server’, the build succeeds but the output shows an error.
  • When specifying nitro.rollupConfig.plugins: [ignore([“jose”])], the error changes from ‘createHash’ to ‘createHmac’.

Logs

08:45:06.136	[info] [nitro] Building Nitro Server (preset: `cloudflare-pages`)
08:45:48.545	[error] [nitro] RollupError: "createHash" is not exported by "node_modules/unenv/runtime/node/crypto/index.mjs", imported by "node_modules/openid-client/node_modules/jose/dist/node/esm/runtime/digest.js".
08:45:48.546	
08:45:48.546	
08:45:48.546	1: import { createHash } from 'crypto';
08:45:48.546	            ^
08:45:48.546	2: const digest = (algorithm, data) => createHash(algorithm).update(data).digest();
08:45:48.546	3: export default digest;
08:45:48.548	[error] "createHash" is not exported by "node_modules/unenv/runtime/node/crypto/index.mjs", imported by "node_modules/openid-client/node_modules/jose/dist/node/esm/runtime/digest.js".
08:45:48.549	  at error (node_modules/nuxt/node_modules/rollup/dist/es/shared/node-entry.js:2128:30)
08:45:48.549	  at Module.error (node_modules/nuxt/node_modules/rollup/dist/es/shared/node-entry.js:13322:16)
08:45:48.549	  at Module.traceVariable (node_modules/nuxt/node_modules/rollup/dist/es/shared/node-entry.js:13707:29)
08:45:48.549	  at ModuleScope.findVariable (node_modules/nuxt/node_modules/rollup/dist/es/shared/node-entry.js:12210:39)
08:45:48.549	  at ReturnValueScope.findVariable (node_modules/nuxt/node_modules/rollup/dist/es/shared/node-entry.js:6953:38)
08:45:48.549	  at Identifier.bind (node_modules/nuxt/node_modules/rollup/dist/es/shared/node-entry.js:8103:40)
08:45:48.550	  at CallExpression.bind (node_modules/nuxt/node_modules/rollup/dist/es/shared/node-entry.js:5749:23)
08:45:48.550	  at CallExpression.bind (node_modules/nuxt/node_modules/rollup/dist/es/shared/node-entry.js:9630:15)
08:45:48.550	  at MemberExpression.bind (node_modules/nuxt/node_modules/rollup/dist/es/shared/node-entry.js:5749:23)
08:45:48.550	  at MemberExpression.bind (node_modules/nuxt/node_modules/rollup/dist/es/shared/node-entry.js:9291:19)
08:45:48.701	error Command failed with exit code 1.
08:45:48.702	info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
08:45:48.727	Failed: build command exited with code: 1
08:45:49.934	Failed: error occurred while running build command

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 24 (4 by maintainers)

Most upvoted comments

Still getting this as well. Considering switching to @Hebilicious repo but that’s a ton of work 😢 .

What features do you need that are missing ?

I don’t think anything is missing - just complaining it is a lot of work to switch libraries. I just put together a proof of concept to investigate however! I left an issue on your repo that is a potential blocker for me, but maybe you’ve run into this before. https://github.com/Hebilicious/authjs-nuxt/issues/43

Until Unenv fixes it there end is there a temporary fix that could be implemented?