Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't resolve 'bufferutil' and 'utf-8-validate' #179

Closed
NickyMeuleman opened this issue Aug 23, 2019 · 14 comments
Closed

Can't resolve 'bufferutil' and 'utf-8-validate' #179

NickyMeuleman opened this issue Aug 23, 2019 · 14 comments

Comments

@NickyMeuleman
Copy link

NickyMeuleman commented Aug 23, 2019

on netlify-lambda build

WARNING in /home/nicky/projects/jason-api/node_modules/subscriptions-transport-ws/node_modules/ws/lib/buffer-util.js
not found: Error: Can't resolve 'bufferutil' in '/home/nicky/projects/jason-api/node_modules/subscriptions-transport-ws/node_modules/ws/lib'

WARNING in /home/nicky/projects/jason-api/node_modules/subscriptions-transport-ws/node_modules/ws/lib/validation.js
not found: Error: Can't resolve 'utf-8-validate' in '/home/nicky/projects/jason-api/node_modules/subscriptions-transport-ws/node_modules/ws/lib'

Despite those errors, ./netlify/functions/graphql still works locally after running netlify-lambda serve

The repo I'm having this issue in is also the mininal reproduction https://github.com/NickyMeuleman/jason-api

@glennreyes
Copy link

glennreyes commented Sep 14, 2019

This can be solved by configuring your webpack externals:

//webpack.functions.js
const nodeExternals = require('webpack-node-externals');

module.exports = {
  externals: [nodeExternals()],
};

However, imho it is more reasonable to have this set up by default so there's no hassle with a custom webpack config when setting up a graphql lambda.

@sw-yx Any thoughts or objections on having this config by default? I'd be happy to open a PR adding it!

@glennreyes
Copy link

One thing I forgot to note, you'll also have to point to your config file in the netlify-lambda command, eg:

netlify-lambda build src/lambda --config webpack.functions.js

@NickyMeuleman
Copy link
Author

Thanks so much for this!
Didn't make the connection I would need this.
I swear I read the README when swapping from netlify dev to netlify lambda...briefly 😊

@PavelMGs
Copy link

PavelMGs commented Nov 5, 2021

If you facing this problem with Next.JS, you just need to add isServer condition for it gonna work

if (isServer) { config.externals = [nodeExternals()] }

@dquanghuy4444
Copy link

If you facing this problem with Next.JS, you just need to add isServer condition for it gonna work

if (isServer) { config.externals = [nodeExternals()] }

hi there , could u public your file , i have problem with nextjs

@PavelMGs
Copy link

PavelMGs commented Dec 10, 2021

If you facing this problem with Next.JS, you just need to add isServer condition for it gonna work
if (isServer) { config.externals = [nodeExternals()] }

hi there , could u public your file , i have problem with nextjs

@dquanghuy4444 I cant do it because of NDA, sorry. You can just show your config

@dquanghuy4444
Copy link

dquanghuy4444 commented Jan 2, 2022

If you facing this problem with Next.JS, you just need to add isServer condition for it gonna work
if (isServer) { config.externals = [nodeExternals()] }

hi there , could u public your file , i have problem with nextjs

@dquanghuy4444 I cant do it because of NDA, sorry. You can just show your config

thank bro , i install fabricjs (https://www.npmjs.com/package/fabric) , and deploy nextjs by netlify and i have this error
7:57:31 PM: ModuleNotFoundError: Module not found: Error: Can't resolve 'bufferutil' in '/opt/build/repo/node_modules/ws/lib'
7:57:31 PM: > Build error occurred
7:57:31 PM: Error: > Build failed because of webpack errors
7:57:31 PM: at /opt/build/repo/node_modules/next/dist/build/index.js:15:924
7:57:31 PM: at async Span.traceAsyncFn (/opt/build/repo/node_modules/next/dist/telemetry/trace/trace.js:6:584)

My next.config.js

const path = require("path")

const withSass = require("@zeit/next-sass")
const nodeExternals = require("webpack-node-externals")

module.exports = withSass({
    /* bydefault config  option Read For More Optios
     here https://github.com/vercel/next-plugins/tree/master/packages/next-sass*/

    cssModules: true
})

module.exports = {
    /* Add Your Scss File Folder Path Here */
    sassOptions: {
        includePaths: [path.join(__dirname, "styles")]
    }
}

module.exports = {
    productionBrowserSourceMaps: false
}

module.exports = {
    webpack: (config, { isServer }) => {
        // eslint-disable-next-line space-before-blocks
        if (isServer) {
            config.externals = nodeExternals()
        }

        return config
    }
}

module.exports = {
    images: {
        domains: ["cdn.shopify.com"]
    }
}

@Jesuspinarte
Copy link

The solution for me was add this ti my next.config.js:

const nodeExternals = require('webpack-node-externals');

const nextConfig = {
  reactStrictMode: true,
};

module.exports = {
  ...nextConfig,
  webpack: (config, { isServer }) => {
    if (!isServer) {
      config.externals = [nodeExternals()];
    }

    return config;
  },
};

I'm using Next 12.1.5

@ThatGuySam
Copy link

ThatGuySam commented Nov 9, 2022

external_node_modules for netlify.toml is supposed to fix this but for some reason, it wouldn't work, however, when I tried including the node_module paths that fixed it.

# netlify.toml
[functions]
  included_files = [
    # For some reason this works to fix "bufferutil" error on
    # Netlify Function and external_node_modules does not
    "node_modules/bufferutil/**", 
    "node_modules/utf-8-validate/**"
  ]

@irzko
Copy link

irzko commented Mar 1, 2023

module.exports = { ...nextConfig, webpack: ( config, { buildId, dev, isServer, defaultLoaders, nextRuntime, webpack } ) => { // Important: return the modified config if (isServer) { config.externals.push({ bufferutil: "bufferutil", "utf-8-validate": "utf-8-validate", }); } return config; }, };

@kapysta-xxl
Copy link

kapysta-xxl commented Jun 29, 2023

next version 13.4.7

npm i bufferutil@4.0.7 --save-dev
npm i utf-8-validate@5.0.10 --save-dev
npm i supports-color@8.1.1 --save-dev

// next.config.js

const nextConfig = {
  reactStrictMode: true,
};

module.exports = {
  ...nextConfig,
  webpack: (config, { isServer }) => {
    if (!isServer) {
      config.externals.push({ bufferutil: "bufferutil", "utf-8-validate": "utf-8-validate", "supports-color": "supports-color" }); 
    }

    return config;
  },
};

@naingaungphyo
Copy link

naingaungphyo commented Sep 17, 2023

next version 13.4.7

npm i bufferutil@4.0.7 --save-dev npm i utf-8-validate@5.0.10 --save-dev npm i supports-color@8.1.1 --save-dev

// next.config.js

const nextConfig = {
  reactStrictMode: true,
};

module.exports = {
  ...nextConfig,
  webpack: (config, { isServer }) => {
    if (!isServer) {
      config.externals.push({ bufferutil: "bufferutil", "utf-8-validate": "utf-8-validate", "supports-color": "supports-color" }); 
    }

    return config;
  },
};

I have no idea what those packages are used for. Can someone clarify it please?

And my another concern is that don't we need those packages in production as we are installing with dev flag? Is not that something Nextjs needs to handle internally for their config?

travis added a commit to storacha/w3up that referenced this issue Oct 10, 2023
when you try to use `@web3-storage/access` in a new next.js repository you get errors like this:

```
Import trace for requested module:
./node_modules/ipfs-utils/src/http/fetch.js
./node_modules/@web3-storage/upload-client/src/store.js
./node_modules/@web3-storage/upload-client/src/index.js
./node_modules/@web3-storage/w3up-client/src/client.js
./node_modules/@web3-storage/w3up-client/src/index.node.js
./app/utils/utils.ts
./app/page.tsx

./node_modules/ws/lib/buffer-util.js
Module not found: Can't resolve 'bufferutil' in '/Users/travis/dev/pl/sample-w3/node_modules/ws/lib'

Import trace for requested module:
./node_modules/ws/lib/buffer-util.js
./node_modules/ws/lib/websocket.js
./node_modules/ws/index.js
./node_modules/isomorphic-ws/node.js
./node_modules/@web3-storage/access/src/utils/ws.js
./node_modules/@web3-storage/access/src/agent-use-cases.js
./node_modules/@web3-storage/access/src/agent.js
./node_modules/@web3-storage/w3up-client/src/index.node.js
./app/utils/utils.ts
./app/page.tsx

./node_modules/ws/lib/validation.js
Module not found: Can't resolve 'utf-8-validate' in '/Users/travis/dev/pl/sample-w3/node_modules/ws/lib'

Import trace for requested module:
./node_modules/ws/lib/validation.js
./node_modules/ws/lib/receiver.js
./node_modules/ws/index.js
./node_modules/isomorphic-ws/node.js
./node_modules/@web3-storage/access/src/utils/ws.js
./node_modules/@web3-storage/access/src/agent-use-cases.js
./node_modules/@web3-storage/access/src/agent.js
./node_modules/@web3-storage/w3up-client/src/index.node.js
./app/utils/utils.ts
./app/page.tsx
```

Which looks like the same thing as netlify/netlify-lambda#179 and shows up a few other times in similar repos.

While we could instruct our users to add some build configuration to go away, we don't use websockets in production in any of our flows and imho we should just remove this dependency. The easiest way to do this is to remove the cli as well, and since we don't use that anywhere that also seems like a good idea.
travis added a commit to storacha/w3up that referenced this issue Oct 10, 2023
when you try to use `@web3-storage/access` in a new next.js repository
you get errors like this:

```
Import trace for requested module:
./node_modules/ipfs-utils/src/http/fetch.js
./node_modules/@web3-storage/upload-client/src/store.js
./node_modules/@web3-storage/upload-client/src/index.js
./node_modules/@web3-storage/w3up-client/src/client.js
./node_modules/@web3-storage/w3up-client/src/index.node.js
./app/utils/utils.ts
./app/page.tsx

./node_modules/ws/lib/buffer-util.js
Module not found: Can't resolve 'bufferutil' in '/Users/travis/dev/pl/sample-w3/node_modules/ws/lib'

Import trace for requested module:
./node_modules/ws/lib/buffer-util.js
./node_modules/ws/lib/websocket.js
./node_modules/ws/index.js
./node_modules/isomorphic-ws/node.js
./node_modules/@web3-storage/access/src/utils/ws.js
./node_modules/@web3-storage/access/src/agent-use-cases.js
./node_modules/@web3-storage/access/src/agent.js
./node_modules/@web3-storage/w3up-client/src/index.node.js
./app/utils/utils.ts
./app/page.tsx

./node_modules/ws/lib/validation.js
Module not found: Can't resolve 'utf-8-validate' in '/Users/travis/dev/pl/sample-w3/node_modules/ws/lib'

Import trace for requested module:
./node_modules/ws/lib/validation.js
./node_modules/ws/lib/receiver.js
./node_modules/ws/index.js
./node_modules/isomorphic-ws/node.js
./node_modules/@web3-storage/access/src/utils/ws.js
./node_modules/@web3-storage/access/src/agent-use-cases.js
./node_modules/@web3-storage/access/src/agent.js
./node_modules/@web3-storage/w3up-client/src/index.node.js
./app/utils/utils.ts
./app/page.tsx
```

Which looks like the same thing as
netlify/netlify-lambda#179 and shows up a few
other times in similar repos.

While we could instruct our users to add some build configuration to go
away, we don't use websockets in production in any of our flows and imho
we should just remove this dependency. The easiest way to do this is to
remove the cli as well, and since we don't use that anywhere that also
seems like a good idea.
@xalteropsx
Copy link

what is for nuxt ?

@muckee
Copy link

muckee commented Jan 9, 2025

I solved this by adding the following .yarnrc.yml file in the project root directory:

nodeLinker: pnp
pnpMode: loose

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests