Skip to content
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

Am getting this error while working on canvas "YouTube timestamp: 1:56:31/ 4:04:52 " #3

Open
0x86e3x4 opened this issue Feb 5, 2024 · 3 comments

Comments

@0x86e3x4
Copy link

0x86e3x4 commented Feb 5, 2024

./node_modules/canvas/build/Release/canvas.node
Module parse failed: Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)

@0x86e3x4 0x86e3x4 changed the title Am getting this error will i was working on canvas Am getting this error while working on canvas "YouTube timestamp: 1:56:31/ 4:04:52 " Feb 5, 2024
@giangutz
Copy link

giangutz commented Feb 6, 2024

Fixed it by adding this on my next.config.mjs file

/** @type {import('next').NextConfig} */
const nextConfig = {
  images: {
    remotePatterns: [
      {
        protocol: "https",
        hostname: "liveblocks.io",
        port: "",
      },
    ],
  },
  webpack: (
    config,
    { buildId, dev, isServer, defaultLoaders, nextRuntime, webpack }
  ) => {
    config.externals.push({ canvas: "commonjs canvas" });
    return config;
  },
};

export default nextConfig;

This config is telling Next.js to exclude canvas from the build process and load it at runtime instead.

@0x86e3x4
Copy link
Author

0x86e3x4 commented Feb 6, 2024

The config provided produces this error: "Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node".

@0x86e3x4 0x86e3x4 mentioned this issue Feb 8, 2024
@rahulAgdev
Copy link

as mentioned above by @giangutz, add a webpack to configure canvas commonjs symbols in your nextjs.config.mjs.

`/** @type {import('next').NextConfig} */
const nextConfig = {
images: {
remotePatterns: [
{
protocol: 'https',
hostname: 'liveblocks.io',
port: ''
}
]
},
webpack: (config) => {
// Add the Webpack externals configuration
config.externals.push({ sharp: 'commonjs sharp', canvas: 'commonjs canvas' });
return config;
}
};

export default nextConfig;
`
This resolved my error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants