esbuild icon indicating copy to clipboard operation
esbuild copied to clipboard

esbuild error with styled-components

Open kysley opened this issue 6 years ago • 2 comments

I'm attempting to migrate a webpack project to snowpack (which uses esbuild tooling).

babel.config.json

{
  "extends": "@snowpack/app-scripts-react/babel.config.json",
  "plugins": [
    "babel-plugin-styled-components"
  ]
}

snowpack.config.js

  module.exports = {
    extends: '@snowpack/app-scripts-react',
    plugins: ['@snowpack/plugin-webpack'],
  }

Reproduction

import styled from 'styled-components'

const Cursor = styled.div`color: black;`

// ...rest of file

When loading the file that contains the styled usage, snowpack fails with the following esbuild error:

events.js:298
      throw er; // Unhandled 'error' event
      ^

Error: write EPIPE
    at afterWriteDispatched (internal/stream_base_commons.js:154:25)
    at writeGeneric (internal/stream_base_commons.js:145:3)
    at Socket._writeGeneric (net.js:780:11)
    at Socket._write (net.js:792:8)
    at doWrite (_stream_writable.js:454:12)
    at writeOrBuffer (_stream_writable.js:436:5)
    at Socket.Writable.write (_stream_writable.js:327:11)
    at C:\Users\re\code\new-dir\node_modules\esbuild\lib\main.js:215:21
    at new Promise (<anonymous>)
    at sendRequest (C:\Users\re\code\new-dir\node_modules\esbuild\lib\main.js:185:14)
    at C:\Users\re\code\new-dir\node_modules\esbuild\lib\main.js:266:5
    at new Promise (<anonymous>)
    at Object.exports.startService (C:\Users\re\code\new-dir\node_modules\esbuild\lib\main.js:134:10)
    at scanImports (C:\Users\re\code\new-dir\node_modules\snowpack\dist-node\index.js:1251:49)
    at async command (C:\Users\re\code\new-dir\node_modules\snowpack\dist-node\index.js:1775:29)
Emitted 'error' event on Socket instance at:
    at errorOrDestroy (internal/streams/destroy.js:128:12)
    at onwriteError (_stream_writable.js:463:3)
    at processTicksAndRejections (internal/process/task_queues.js:86:21) {
  errno: -4047,
  code: 'EPIPE',
  syscall: 'write'
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

With the styled-components code commented out, snowpack (esbuild) compiles the code without problem.

A snippet to trigger the above error:

var esbuild = require('esbuild');
esbuild.startService().then(console.log);

kysley avatar May 30 '20 17:05 kysley

Just chiming in to say that I think our debugging showed that this isn't actually styled-components related. The issue appears to just be that running the snippet at the bottom results in the EPIPE issue on @kysley's machine.

var esbuild = require('esbuild');
esbuild.startService().then(console.log);

Error: write EPIPE
    at afterWriteDispatched (internal/stream_base_commons.js:154:25)
    at writeGeneric (internal/stream_base_commons.js:145:3)
    at Socket._writeGeneric (net.js:780:11)
    at Socket._write (net.js:792:8)
    at doWrite (_stream_writable.js:454:12)
    at writeOrBuffer (_stream_writable.js:436:5)
    at Socket.Writable.write (_stream_writable.js:327:11)
    at C:\Users\re\code\new-dir\node_modules\esbuild\lib\main.js:215:21

More context here: https://www.pika.dev/npm/snowpack/discuss/262

FredKSchott avatar May 30 '20 18:05 FredKSchott

After bumping snowpack tooling versions, I am no longer encountering this error. Closing.

kysley avatar May 31 '20 17:05 kysley