next-shared-cache icon indicating copy to clipboard operation
next-shared-cache copied to clipboard

next/constants module not found when setting instrumentation

Open ffigueroal opened this issue 1 year ago • 2 comments

Brief Description of the Bug

We are trying to test the new pre-rendered page population feature, but we're stuck on creating the instrumentation file and enabling instrumentationHook in next.config.js. The error we got is the following:

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/project/path/node_modules/next/constants' imported from /project/path/node_modules/@neshca/cache-handler/dist/instrumentation/instrumentation.js Did you mean to import next/constants.js?.

Does this have anything to do with Next's version? We're stuck on version 13 for a while now.

Severity Major

Frequency of Occurrence Always

Steps to Reproduce

  1. Setting up the example instrumentation file.
  2. Enable instrumentationHook in next.config.js.
  3. Run npm run dev or npm run build and then npm start.

Expected vs. Actual Behavior

We expect that the pre-rendered pages population feature can work smoothly for all the next versions that supports it.

Environment:

  • OS: MacOS
  • Node.js version: 18.20.3
  • @neshca/cache-handler version: 1.7.3
  • next version: 13.5.7

ffigueroal avatar Sep 23 '24 23:09 ffigueroal

@ffigueroal hello! I am sorry it took so long to answer.

If you are developing your project in a monorepo please ensure that the problem isn't caused by misconfigured tracing. Refer to this Next.js documentation on outputFileTracingRoot at https://nextjs.org/docs/13/app/api-reference/next-config-js/output#caveats.

better-salmon avatar Oct 16 '24 15:10 better-salmon

Howdy! We've experienced similar thing (not a monorepo setup) where also setting experimental esmExternals: falsein next.config.js removes the errors involving ERR_MODULE_NOT_FOUND of next/constants.

Also noticed by setting the following in the config, it seems to work correct. transpilePackages: ['@neshca/cache-handler']

This leads me to think that there's something going on with how the package is bundled or similar?

alexanderchabo avatar Nov 01 '24 12:11 alexanderchabo