Can't resolve 'canvas' on next.js serverless app
See original GitHub issueWhat’s the problem
I built a next.js application with serveless option, but simply importing this library it throws this error:
Failed to compile.
ModuleNotFoundError: Module not found: Error: Can't resolve 'canvas' in '/.../node_modules/jsdom/lib/jsdom'
> Build error occurred
I already tried to add canvas library but this doesn’t fix the problem and it throws another error.
Step to reproduce
Add to next.config.js
:
module.exports = {
target: 'serverless'
}
Run next build
Basic Info:
- “isomorphic-dompurify”: “^0.12.0”,
- “next”: “^10.0.8”,
- “react”: “^17.0.1”,
- “react-dom”: “^17.0.1”
This issue could be related to #35 , but i don’t use umijs.
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (6 by maintainers)
Top Results From Across the Web
Nextjs deploy error after installing remark-prism package
After installing remark-prism, I get this deploy error: ModuleNotFoundError: Module not found: Error: Can't resolve 'canvas' in ...
Read more >module-not-found
The module you're trying to import uses Node. js specific modules, for example dns , outside of getStaticProps / getStaticPaths / getServerSideProps.
Read more >Node Canvas on Vercel Serverless Function
I'm generating images on the server based on data users send to the API route I have in Next.js using the canvas package....
Read more >Serverless Nextjs Plugin
It is the component's job to deploy your application ensuring parity with all of next's features we know and love. We try to...
Read more >Untitled
Simple drawing canvas on your browser using HTML canvas and Nextjs. ... Actions Projects Security Insights New issue Can't resolve 'canvas' on next....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I was also having this issue with SvelteKit using the Node adapter. Installing
canvas
solved the issue, but it would be nice if there were also a solution for serverless.@EnricoNapolitan did you find a solution? I’m encountering something similar with Gatsby.