Open daanboer opened 1 week ago
Hmm, pretty weird, looks like some kind of path resolution issue
import { ... } from 'rust-lib'
is somehow resolved to a path that's relative to packages/web-app
, the project root (require("../rust-lib/dist/index.node")
.
But then that require() call is placed in packages/web-app/.next/server/app/page.js
, so the ../
ends up being incorrect... Manually editing page.js
to do require("../../../../rust-lib/dist/index.node")
fixes the problem.
Link to the code that reproduces this issue
https://github.com/daanboer/next-load-native-module
To Reproduce
Install dependencies.
Build the
rust-lib
package (needs a working rust installation).Try to build the
web-app
package.Current vs. Expected behavior
I expect the
greet
function from therust-lib
package to be imported and called. Instead theweb-app
build process throws the following error:[cause]: Error: Cannot find module '../rust-lib/dist/index.node'
.Full build logs
``` > web-app@0.1.0 build /home/daan/git/next-load-native-module/packages/web-app > next build ▲ Next.js 15.0.0 Creating an optimized production build ... ✓ Compiled successfully ✓ Linting and checking validity of types Collecting page data .Error: Failed to collect configuration for / at /home/daan/git/next-load-native-module/node_modules/.pnpm/next@15.0.0_react-dom@19.0.0-rc-65a56d0e-20241020_react@19.0.0-rc-65a56d0e-20241020__react@19.0.0-rc-65a56d0e-20241020/node_modules/next/dist/build/utils.js:1130:23 at process.processTicksAndRejections (node:internal/process/task_queues:105:5) at async Span.traceAsyncFn (/home/daan/git/next-load-native-module/node_modules/.pnpm/next@15.0.0_react-dom@19.0.0-rc-65a56d0e-20241020_react@19.0.0-rc-65a56d0e-20241020__react@19.0.0-rc-65a56d0e-20241020/node_modules/next/dist/trace/trace.js:157:20) { [cause]: Error: Cannot find module '../rust-lib/dist/index.node' Require stack: - /home/daan/git/next-load-native-module/packages/web-app/.next/server/app/page.js - /home/daan/git/next-load-native-module/node_modules/.pnpm/next@15.0.0_react-dom@19.0.0-rc-65a56d0e-20241020_react@19.0.0-rc-65a56d0e-20241020__react@19.0.0-rc-65a56d0e-20241020/node_modules/next/dist/server/require.js - /home/daan/git/next-load-native-module/node_modules/.pnpm/next@15.0.0_react-dom@19.0.0-rc-65a56d0e-20241020_react@19.0.0-rc-65a56d0e-20241020__react@19.0.0-rc-65a56d0e-20241020/node_modules/next/dist/server/load-components.js - /home/daan/git/next-load-native-module/node_modules/.pnpm/next@15.0.0_react-dom@19.0.0-rc-65a56d0e-20241020_react@19.0.0-rc-65a56d0e-20241020__react@19.0.0-rc-65a56d0e-20241020/node_modules/next/dist/build/utils.js - /home/daan/git/next-load-native-module/node_modules/.pnpm/next@15.0.0_react-dom@19.0.0-rc-65a56d0e-20241020_react@19.0.0-rc-65a56d0e-20241020__react@19.0.0-rc-65a56d0e-20241020/node_modules/next/dist/build/worker.js - /home/daan/git/next-load-native-module/node_modules/.pnpm/next@15.0.0_react-dom@19.0.0-rc-65a56d0e-20241020_react@19.0.0-rc-65a56d0e-20241020__react@19.0.0-rc-65a56d0e-20241020/node_modules/next/dist/compiled/jest-worker/processChild.js at Module._resolveFilename (node:internal/modules/cjs/loader:1248:15) at /home/daan/git/next-load-native-module/node_modules/.pnpm/next@15.0.0_react-dom@19.0.0-rc-65a56d0e-20241020_react@19.0.0-rc-65a56d0e-20241020__react@19.0.0-rc-65a56d0e-20241020/node_modules/next/dist/server/require-hook.js:55:36 at Module._load (node:internal/modules/cjs/loader:1074:27) at TracingChannel.traceSync (node:diagnostics_channel:315:14) at wrapModuleLoad (node:internal/modules/cjs/loader:217:24) at Module.require (node:internal/modules/cjs/loader:1339:12) at mod.require (/home/daan/git/next-load-native-module/node_modules/.pnpm/next@15.0.0_react-dom@19.0.0-rc-65a56d0e-20241020_react@19.0.0-rc-65a56d0e-20241020__react@19.0.0-rc-65a56d0e-20241020/node_modules/next/dist/server/require-hook.js:65:28) at require (node:internal/modules/helpers:135:16) at 7215 (/home/daan/git/next-load-native-module/packages/web-app/.next/server/app/page.js:1:31238) at t (/home/daan/git/next-load-native-module/packages/web-app/.next/server/webpack-runtime.js:1:127) { code: 'MODULE_NOT_FOUND', requireStack: [ '/home/daan/git/next-load-native-module/packages/web-app/.next/server/app/page.js', '/home/daan/git/next-load-native-module/node_modules/.pnpm/next@15.0.0_react-dom@19.0.0-rc-65a56d0e-20241020_react@19.0.0-rc-65a56d0e-20241020__react@19.0.0-rc-65a56d0e-20241020/node_modules/next/dist/server/require.js', '/home/daan/git/next-load-native-module/node_modules/.pnpm/next@15.0.0_react-dom@19.0.0-rc-65a56d0e-20241020_react@19.0.0-rc-65a56d0e-20241020__react@19.0.0-rc-65a56d0e-20241020/node_modules/next/dist/server/load-components.js', '/home/daan/git/next-load-native-module/node_modules/.pnpm/next@15.0.0_react-dom@19.0.0-rc-65a56d0e-20241020_react@19.0.0-rc-65a56d0e-20241020__react@19.0.0-rc-65a56d0e-20241020/node_modules/next/dist/build/utils.js', '/home/daan/git/next-load-native-module/node_modules/.pnpm/next@15.0.0_react-dom@19.0.0-rc-65a56d0e-20241020_react@19.0.0-rc-65a56d0e-20241020__react@19.0.0-rc-65a56d0e-20241020/node_modules/next/dist/build/worker.js', '/home/daan/git/next-load-native-module/node_modules/.pnpm/next@15.0.0_react-dom@19.0.0-rc-65a56d0e-20241020_react@19.0.0-rc-65a56d0e-20241020__react@19.0.0-rc-65a56d0e-20241020/node_modules/next/dist/compiled/jest-worker/processChild.js' ] } } > Build error occurred Error: Failed to collect page data for / at /home/daan/git/next-load-native-module/node_modules/.pnpm/next@15.0.0_react-dom@19.0.0-rc-65a56d0e-20241020_react@19.0.0-rc-65a56d0e-20241020__react@19.0.0-rc-65a56d0e-20241020/node_modules/next/dist/build/utils.js:1233:15 at process.processTicksAndRejections (node:internal/process/task_queues:105:5) { type: 'Error' } Collecting page data . ELIFECYCLE Command failed with exit code 1. ```Provide environment information
Which area(s) are affected? (Select all that apply)
Not sure
Which stage(s) are affected? (Select all that apply)
next dev (local), next build (local)
Additional context
The same setup compiles when using Next.js
v14.2.13
forweb-app
. It seems that the bug is introduced inv14.2.14
.