Error when using the Nodejs Sharp module. Module parse failed: Unexpected character '' (1: 0)

Viewed 1072

When running webpack I have received this error "WARNING in ./node_modules/sharp/build/Release/sharp.node 1: 0 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) @ ./node_modules/sharp/lib/constructor.js 11: 2-40 @ ./node_modules/sharp/lib/index.js "

Sharp was installed with the yarn add. My operating system is ubuntu 18.04 x86_64. How can I solve this problem?

1 Answers

If you use webpack, use node-loader

Install it: npm i -D node-loader

In webpack.config.js:

module: {
  rules: [
    { test: /\.ts$/, loader: "ts-loader" },  
    { test: /\.node$/, use: "node-loader"}
  ]
}
Related