Node-slack-sdk: Can't resolve bufferutil / utf-8-validate

Created on 26 Mar 2019  路  2Comments  路  Source: slackapi/node-slack-sdk

Description

Describe your issue here.

What type of issue is this? (place an x in one of the [ ])

  • [x] bug
  • [ ] enhancement (feature request)
  • [ ] question
  • [ ] documentation related
  • [ ] testing related
  • [ ] discussion

Requirements (place an x in each of the [ ])

  • [x] I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • [x] I've read and agree to the Code of Conduct.
  • [x] I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Old bug #559 seems to be the same issue, but I can't re-open it.

Reproducible in:

@slack/client version: 4.12.0

node version: 8.12.0 (npm 6.9.0)

OS version(s): macOS 10.14 Mojave

Steps to reproduce:

  1. Build a little typescript demo, eg
  import { WebClient } from '@slack/client'
  const web = new WebClient(process.env.SLACK_TOKEN)
  const resp = await web.chat.postMessage(
    {
      channel: process.env.CHANNEL,
      text: "Hello!"
    }
  )
  1. Compile with webpack
  2. Warnings on build:
WARNING in ./node_modules/ws/lib/buffer-util.js
Module not found: Error: Can't resolve 'bufferutil' in '/xyz/node_modules/ws/lib'
 @ ./node_modules/ws/lib/buffer-util.js
 @ ./node_modules/ws/lib/receiver.js
 @ ./node_modules/ws/index.js
 @ ./node_modules/@slack/client/dist/RTMClient.js
 @ ./node_modules/@slack/client/dist/index.js
 @ ./src/handler.ts

WARNING in ./node_modules/ws/lib/validation.js
Module not found: Error: Can't resolve 'utf-8-validate' in '/xyz/node_modules/ws/lib'
 @ ./node_modules/ws/lib/validation.js
 @ ./node_modules/ws/lib/receiver.js
 @ ./node_modules/ws/index.js
 @ ./node_modules/@slack/client/dist/RTMClient.js
 @ ./node_modules/@slack/client/dist/index.js
 @ ./src/handler.ts

Expected result:

No warnings on build

question

Most helpful comment

Actually, I'm trying to use it in an AWS Lambda with Serverless framework!

To build the full example, you can use these commands:

mkdir slacktest
cd slacktest/
npx sls create -t aws-nodejs-typescript -n slacktest
npm i
npm i @slack/client

Then add this file as handler.ts:

import { APIGatewayProxyHandler } from 'aws-lambda';
import { WebClient } from '@slack/client'

export const hello: APIGatewayProxyHandler = async (event, context) => {
  const web = new WebClient(process.env.SLACK_TOKEN)
  const slackresp = await web.chat.postMessage(
    {
      channel: process.env.CHANNEL,
      text: "Hello!"
    })
  const resp = {
    statusCode: 200,
    body: JSON.stringify(slackresp)
  }
  return resp
}

And run npx sls package.

So personally I'm not (that) worried about bundle size. But splitting up the package sounds fine!

All 2 comments

Hi @alexjurkiewicz 馃憢

Sorry for the trouble. We haven't explicitly supported browser-specific use cases with this package, but I'd still like to help you to get it to work. Are you in fact trying to bundle with webpack for use in the browser?

I think we'll be able to solve this problem with v5.0.0, which is going to be released very soon*. In that release, @slack/client will be separated into a few packages and so you'll be able to require only @slack/web-api if all you need is the WebClient. I haven't tried bundling this new package myself just yet, but if you're willing to give it a shot for us and report back what you find, we'd appreciate it. 馃槃

*Very soon likely means before the end of the week.

Actually, I'm trying to use it in an AWS Lambda with Serverless framework!

To build the full example, you can use these commands:

mkdir slacktest
cd slacktest/
npx sls create -t aws-nodejs-typescript -n slacktest
npm i
npm i @slack/client

Then add this file as handler.ts:

import { APIGatewayProxyHandler } from 'aws-lambda';
import { WebClient } from '@slack/client'

export const hello: APIGatewayProxyHandler = async (event, context) => {
  const web = new WebClient(process.env.SLACK_TOKEN)
  const slackresp = await web.chat.postMessage(
    {
      channel: process.env.CHANNEL,
      text: "Hello!"
    })
  const resp = {
    statusCode: 200,
    body: JSON.stringify(slackresp)
  }
  return resp
}

And run npx sls package.

So personally I'm not (that) worried about bundle size. But splitting up the package sounds fine!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

thepont picture thepont  路  17Comments

mpcowan picture mpcowan  路  15Comments

aoberoi picture aoberoi  路  16Comments

aoberoi picture aoberoi  路  12Comments

aoberoi picture aoberoi  路  10Comments