fastembed-js icon indicating copy to clipboard operation
fastembed-js copied to clipboard

Loader error in NextJS 13

Open pmcb99 opened this issue 1 year ago • 4 comments

I'm getting this error with NextJS 13, running Node 20.8:

./node_modules/@anush008/tokenizers-darwin-universal/tokenizers.darwin-universal.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) Tried configuring a loader with

module.exports = { externals: { '@anush008/tokenizers-darwin-universal': 'commonjs @anush008/tokenizers-darwin-universal' }, };

and

module.exports = { module: { rules: [ { test: /\.node$/, use: 'node-loader' } ] }, };

pmcb99 avatar Oct 26 '23 15:10 pmcb99

Hey. The Rust based tokenizers library uses https://github.com/napi-rs/napi-rs for Node bindings. From the error, it appears like Webpack is having issues with bundling it.

Could you try using fastembed in a regular Node application without Webpack? To see if it works and we can narrow the problem down to a Webpack compatibility issue.

Anush008 avatar Oct 26 '23 16:10 Anush008

Hey. The Rust based tokenizers library uses https://github.com/napi-rs/napi-rs for Node bindings. From the error, it appears like Webpack is having issues with bundling it.

Could you try using fastembed in a regular Node application without Webpack? To see if it works and we can narrow the problem down to a Webpack compatibility issue.

Yeah I'm able to get that running so must be a webpack issue

pmcb99 avatar Oct 26 '23 17:10 pmcb99

this next config and node-loader solved it for me

/** @type {import('next').NextConfig} */
const nextConfig = {
  webpack: (config) => {
    config.module.rules.push({
      test: /\.node$/,
      use: 'node-loader',
    });
    return config;
  },
};

export default nextConfig;

sorokinvj avatar Apr 15 '24 14:04 sorokinvj

Thanks for the insight @sorokinvj

Anush008 avatar Apr 15 '24 16:04 Anush008