-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Module parse failed: /canvas/build/Release/canvas.node Unexpected character '�' #867
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is because Are you intending to run the resulting bundle with Node.js or in the browser? |
I intend to run the bundle with Node.js. @LinusU do you have a way to make it work? |
@playground I hadn't heard of using webpack for node.js until now, but... I think the only way this could work is if you use the |
For me providing the canvas as an external empty object worked:
In my case I am using webpack with karma to run unit test. Since canvas is not part of any test mocking it with an empty object did the trick. |
I have this issue on externals : { canvas: {} } |
I fixed it in this way with next 14.0.4 import './src/env.mjs';
/** @type {import('next').NextConfig} */
const nextConfig = {
webpack: (
config,
{ buildId, dev, isServer, defaultLoaders, nextRuntime, webpack }
) => {
config.externals.push({ canvas: 'commonjs canvas' })
return config
},
};
export default nextConfig; |
You're My Hero |
This works! Thanks! |
how to fix it in nuxtjs, thanks everyone |
Adds a module factory to use the Canvas API when in the browser environment and node-canvas when in Node.js. Next.js webpack config necessary to load node-canvas properly. See: Automattic/node-canvas#867 (comment)
Hi Community I am currently stuck in canvas error in next js 14.1.3 and using the "fabric": "^5.3.0", `⨯ ./node_modules/canvas/build/Release/canvas.node Import trace for requested module: can anyone help me in this |
|
https://dev.to/ziqinyeow/step-by-step-on-how-to-setup-fabricjs-in-the-nextjs-app-3hi3 I followed the steps here. My
|
build: { |
It works! Thankyou ❤ |
i have the same issue with angular, ng2-pdf-viewer used canvas internally and while building the project i'm getting this issue |
When build with webpack, it throws these errors.
I'm using fabric.js 1.7.3 which has a dependencies on canvas 1.6.2
SyntaxError: Unexpected character '�' (1:0)
at Parser.pp$4.raise (/test1/node/ow-dig/node_modules/webpack/node_modules/acorn/dist/acorn.js:2221:15)
at Parser.pp$7.getTokenFromCode (/test1/node/ow-dig/node_modules/webpack/node_modules/acorn/dist/acorn.js:2756:10)
at Parser.pp$7.readToken (/test1/node/ow-dig/node_modules/webpack/node_modules/acorn/dist/acorn.js:2477:17)
at Parser.pp$7.nextToken (/test1/node/ow-dig/node_modules/webpack/node_modules/acorn/dist/acorn.js:2468:15)
at Parser.parse (/test1/node/ow-dig/node_modules/webpack/node_modules/acorn/dist/acorn.js:515:10)
at Object.parse (/test1/node/ow-dig/node_modules/webpack/node_modules/acorn/dist/acorn.js:3098:39)
at Parser.parse (/test1/node/ow-dig/node_modules/webpack/lib/Parser.js:902:15)
at DependenciesBlock. (/test1/node/ow-dig/node_modules/webpack/lib/NormalModule.js:104:16)
at DependenciesBlock.onModuleBuild (/test1/node/ow-dig/node_modules/webpack-core/lib/NormalModuleMixin.js:310:10)
at nextLoader (/test1/node/ow-dig/node_modules/webpack-core/lib/NormalModuleMixin.js:275:25)
at /test1/node/ow-dig/node_modules/webpack-core/lib/NormalModuleMixin.js:259:5
at Storage.finished (/test1/node/ow-dig/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:38:16)
at /test1/node/ow-dig/node_modules/graceful-fs/graceful-fs.js:78:16
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:439:3)
@ ./~/canvas/lib/bindings.js 3:17-51
The text was updated successfully, but these errors were encountered: