node-lz4 icon indicating copy to clipboard operation
node-lz4 copied to clipboard

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

Open isaced opened this issue 1 year ago • 6 comments
trafficstars

 ⨯ ./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

isaced avatar Feb 17 '24 14:02 isaced

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.

RoboCafaz avatar Mar 07 '24 03:03 RoboCafaz

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.

Tukajo avatar Jul 23 '24 21:07 Tukajo

@Tukajo you can try this:

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

export default nextConfig;

isaced avatar Jul 28 '24 01:07 isaced

@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 avatar Jul 30 '24 18:07 Tukajo

@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

Andriy-Kulak avatar Aug 06 '24 18:08 Andriy-Kulak

@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.

Tukajo avatar Aug 24 '24 01:08 Tukajo