preactjs / next-plugin-preact

Next.js plugin for preact X
395 stars 9 forks source link

error building with latest preact, next.js: Cannot find module 'webpack' #18

Closed srdjan closed 3 years ago

srdjan commented 3 years ago

Reproduction

https://github.com/srdjan/next-repros

Steps to reproduce

npm run build

Expected Behavior

successful build

Actual Behavior

Build error occurred { Error: Cannot find module 'webpack' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15) at Function.Module._resolveFilename (/Users/srdjans/Code/next-repros/node_modules/module-alias/index.js:49:29) at Function.Module._load (internal/modules/cjs/loader.js:562:25) at Module.require (internal/modules/cjs/loader.js:692:17) at require (internal/modules/cjs/helpers.js:25:18) at Object. (/Users/srdjans/Code/next-repros/node_modules/@prefresh/webpack/src/index.js:1:17) at Module._compile (internal/modules/cjs/loader.js:778:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10) at Module.load (internal/modules/cjs/loader.js:653:32) at tryModuleLoad (internal/modules/cjs/loader.js:593:12) at Function.Module._load (internal/modules/cjs/loader.js:585:3) at Module.require (internal/modules/cjs/loader.js:692:17) at require (internal/modules/cjs/helpers.js:25:18) at Object. (/Users/srdjans/Code/next-repros/node_modules/@prefresh/next/src/index.js:1:18) at Module._compile (internal/modules/cjs/loader.js:778:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10) code: 'MODULE_NOT_FOUND' }

marvinhagemeister commented 3 years ago

Looks like the canary builds of nextjs inline webpack as a dependency. Therefore it won't show up in node_modules anymore.

Downgrading next to the latest stable build works fine.

@JoviDeCroock can you transfer this issue to the prefresh repo?

srdjan commented 3 years ago

yeah, thanks. alternatively installing webpack (at least while this gets sorted) works ...

marvinhagemeister commented 3 years ago

Re-opening because it should work by default without additional user interactions.

sventschui commented 3 years ago

@JoviDeCroock do you already have a plan how to mitigate this in @prefresh/next? I think we should check whether the required webpack utils are part of nextjs' bundled webpack distro and use them instead of importing webpack (if available)

JoviDeCroock commented 3 years ago

Hmm, does next export the utils?

jnv commented 3 years ago

This seems to be fixed with the recently released next@10.0.8, can someone else verify?

srdjan commented 3 years ago

confirming that next@10.0.8 fixes this issue

srdjan commented 3 years ago

since I opened it - I'll close it :)

jnv commented 3 years ago

Cool, however mind that Next 10.0.8 has trouble with .env files: https://github.com/vercel/next.js/pull/22879 – if you need that, it should be fixed in canary.