Next.js Discord

Discord Forum

Module parse failed: Unexpected character '' (1:2)

Unanswered
Northeast Congo Lion posted this in #help-forum
Open in Discord
Northeast Congo LionOP
I'm trying to use a library that needs jsdom, which was complaining canvas couldn't be found, so I installed it (npm install cavnas) but got the following error:

 ⨯ ./node_modules/canvas/build/Release/canvas.node
Module parse failed: Unexpected character '�' (1:2)
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)

Import trace for requested module:
./node_modules/canvas/build/Release/canvas.node
./node_modules/canvas/lib/bindings.js
./node_modules/canvas/index.js
./node_modules/jsdom/lib/jsdom/utils.js
./node_modules/jsdom/lib/jsdom/browser/Window.js
./node_modules/jsdom/lib/api.js
./node_modules/skyblock.js/index.js
./src/app/seen/page.tsx


this is my next.config.js
/** @type {import('next').NextConfig} */
const nextConfig = {
    webpack: (config, { isServer }) => {
        if (!isServer) {
            config.resolve = {
                ...config.resolve,
                fallback: {
                    // fixes proxy-agent dependencies
                    net: false,
                    dns: false,
                    tls: false,
                    assert: false,
                    child_process: false,
                    fs: false,
                    perf_hooks: false,
                }
            };
        }

        config.module.exprContextCritical = false; // Workaround to suppress next-i18next warning, see https://github.com/isaachinman/next-i18next/issues/1545
    
        return config;
    },
}

module.exports = nextConfig

8 Replies

Northeast Congo LionOP
please ping me if responding btw
Northeast Congo LionOP
bump
@Northeast Congo Lion Try to add this
/** @type {import('next').NextConfig} */
const nextConfig = {
  webpack: (config) => {
    config.externals.push({
      canvas: 'canvas'
    })

    return config
  }
}

export default nextConfig
is it normal for dependencies to not be installed? butterutil, utf-8-validate and encoding are all missing (i'll install them just wondering)
the page flashes then disappears, this is in the console
Northeast Congo LionOP
i just made the jsdom dependency 'optional' in the library since I have control so hopefully that fixes it