Anush008 / fastembed-js

Library to generate vector embeddings in NodeJS
https://www.npmjs.com/package/fastembed/
MIT License
64 stars 5 forks source link

Loader error in NextJS 13 #9

Closed pmcb99 closed 2 months ago

pmcb99 commented 10 months ago

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' } ] }, };

Anush008 commented 10 months ago

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.

pmcb99 commented 10 months ago

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

sorokinvj commented 4 months ago

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;
Anush008 commented 4 months ago

Thanks for the insight @sorokinvj