pierrec / node-lz4

LZ4 fast compression algorithm for NodeJS
MIT License
438 stars 97 forks source link

Module not found: Can't resolve '../build/Release/xxhash' #118

Open isaced opened 6 months ago

isaced commented 6 months ago
 ⨯ ./node_modules/lz4/lib/utils.js:4:10
Module not found: Can't resolve '../build/Release/xxhash'

https://nextjs.org/docs/messages/module-not-found

Import trace for requested module:
./node_modules/lz4/lib/static.js
./node_modules/lz4/lib/lz4.js
./node_modules/@alicloud/gateway-sls-util/dist/client.js
./node_modules/@alicloud/gateway-sls/dist/client.js
./node_modules/@alicloud/sls20201230/dist/client.js
./lib/sls.ts
 ⨯ ./node_modules/lz4/lib/utils.js:4:10
Module not found: Can't resolve '../build/Release/xxhash'

https://nextjs.org/docs/messages/module-not-found

Import trace for requested module:
./node_modules/lz4/lib/static.js
./node_modules/lz4/lib/lz4.js
./node_modules/@alicloud/gateway-sls-util/dist/client.js
./node_modules/@alicloud/gateway-sls/dist/client.js
./node_modules/@alicloud/sls20201230/dist/client.js
./lib/sls.ts

ENV:

  • lz4: v0.6.5
  • node: v20.10.0
  • npm: 10.2.3
RoboCafaz commented 6 months ago

Check your node_modules/lz4/build/Release folder. You should see an lz4.node and xxhash.node file in there. If not, try re-running npm install or yarn install.

You'll need to make sure whatever is running the environment recognizes those files as modules. For example, with jest you have to add node to the moduleFileExtensions list.

Tukajo commented 1 month ago

Y'all ever get any further with this? @RoboCafaz, @isaced struggling with the same issue. I even tried wrapping some of the stuff manually and had no luck.

isaced commented 1 month ago

@Tukajo you can try this:

const nextConfig = {
  output: "standalone",
  experimental: {
    serverComponentsExternalPackages: ["lz4"],  // <-add this
  },
};

export default nextConfig;
Tukajo commented 1 month ago

@isaced thanks for the suggestion! I should have been more clear 🙂.

I'm actually just using a regular nodejs env. Trying to basically bundle an aws lambda. So no nextjs involved unfortunately.

Andriy-Kulak commented 1 month ago

@isaced thanks for the suggestion! I should have been more clear 🙂.

I'm actually just using a regular nodejs env. Trying to basically bundle an aws lambda. So no nextjs involved unfortunately.

@Tukajo any luck with solving this? i am having the same issue on lambda

Tukajo commented 1 week ago

@Andriy-Kulak I went down a deep deep rabbithole that lead me to a circular series of threads where people were in a stalemate on resolving this.

Some folks were essentially arguing that this will not be implemented, since the new node fetch does not resolve local file URIs anymore as of the latest node versions. They refused to do it because various fetch specs from WinterCG specify that "file resolving" is left up to the reader as exercise see: image https://fetch.spec.wintercg.org/

I don't personally agree with this argument all that much since honestly it is surprising to me that node would allow file fetching up until now and basically break a ton of functionality. I don't know who's "problem" this is to fix.

Since there is this stalemate, and lz4 mostly relies on fetch resolving local wasm files for lz4, I don't foresee any fix any time soon.

I moved on to using different compression algorithms for my work that did not rely on local file fetching, or had out-of-the-box support for file fetching.

My use-case was identical to yours, this was lambda code.

Sorry I couldn't help more.