I’m trying to deploy my next.js website for the first time on Netlify. Everything works and builds properly locally, but when I try on Netlify, I get dependency errors. I’ve discovered that npm install canvas actually installs canvas.node (which is incorrect, but not changeable, since remark-prism requres jsdom which requires canvas), so I also installed node-loader and set up my next.config.js as follows:
28 PM: ./node_modules/canvas/build/Release/canvas.node
2:55:28 PM: Module parse failed: Unexpected character ‘’ (1:0)
2:55:28 PM: You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See Concepts | webpack
2:55:28 PM: (Source code omitted for this binary file)
2:55:28 PM: > Build error occurred
2:55:28 PM: Error: > Build failed because of webpack errors
2:55:28 PM: at /opt/build/repo/node_modules/next/dist/build/index.js:397:19
2:55:28 PM: at async Span.traceAsyncFn (/opt/build/repo/node_modules/next/dist/telemetry/trace/trace.js:60:20)
2:55:28 PM: at async Object.build [as default] (/opt/build/repo/node_modules/next/dist/build/index.js:77:25)
2:55:28 PM:
2:55:28 PM: ────────────────────────────────────────────────────────────────
I tried to post the full build log, but got an error about only being able to post 6 links at a time?
Build problems? Link or paste the FULL build log & build settings screenshot
Hey hrishikesh - I’ve read that page several times, and tried several methods of extending the webpack. This is, though, my first time working with both webpack and Next.js. I tried swapping back to what is listed on that page (below), but get errors about missing externals
12:59:35 PM: Critical dependency: the request of a dependency is an expression
12:59:35 PM: ./node_modules/ws/lib/buffer-util.js
12:59:35 PM: Module not found: Can’t resolve ‘bufferutil’ in ‘/opt/build/repo/node_modules/ws/lib’
12:59:35 PM: ./node_modules/ws/lib/validation.js
which is what I was trying to circumvent. I don’t see anything in this page about loading externals, so I’m not sure how Next.js handles it. Any other sources I’ve googled seem quite different, so I don’t think they will help.
I was stuck on this exact same error trying to use Prism on Netlify for a few hours today and finally found a solution, so going to post what worked for me.
I was using NextJS 12, and needed to downgrade to NextJS 11 and also set my target to be ‘experimental-server less-trace’. There are more details available here if you’re interested: