Webpack Errors from Middleware Imports
Link to the code that reproduces this issue
https://github.com/creativeindustriesgroup/nextjs-webpack-middleware-issue
To Reproduce
When importing certain packages into middleware, accessing any page which triggers the middleware will throw the error:
./node_modules/farmhash-modern/bin/bundler/farmhash_modern_bg.wasm Module parse failed: Unexpected character '' (1:0) The module seem to be a WebAssembly module, but module is not flagged as WebAssembly module for webpack. BREAKING CHANGE: Since webpack 5 WebAssembly is not enabled by default and flagged as experimental feature. You need to enable one of the WebAssembly experiments via 'experiments.asyncWebAssembly: true' (based on async modules) or 'experiments.syncWebAssembly: true' (like webpack 4, deprecated). For files that transpile to WebAssembly, make sure to set the module type in the 'module.rules' section of the config (e. g. 'type: "webassembly/async"'). (Source code omitted for this binary file)
Current vs. Expected behavior
Packages such as firebase-admin, with-electron-typescript and mssql cannot be imported into middleware. I would expect these packages to be importable in order to perform operations such as token validation (in the case of firebase) in middleware.
Provide environment information
Operating System:
Platform: darwin
Arch: x64
Version: Darwin Kernel Version 22.3.0: Mon Jan 30 20:42:11 PST 2023; root:xnu-8792.81.3~2/RELEASE_X86_64
Available memory (MB): 32768
Available CPU cores: 16
Binaries:
Node: 20.13.1
npm: 10.5.2
Yarn: N/A
pnpm: N/A
Relevant Packages:
next: 14.2.4 // Latest available version is detected (14.2.4).
eslint-config-next: N/A
react: 18.3.1
react-dom: 18.2.0
typescript: N/A
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
Middleware, Webpack
Which stage(s) are affected? (Select all that apply)
next dev (local), next build (local)
Additional context
Issue seems similar in:
- https://github.com/vercel/next.js/issues/49581
- https://github.com/vercel/next.js/discussions/59736
- https://github.com/vercel/next.js/discussions/63028