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

fix(esbuild): import esbuild correctly #783

Merged
merged 1 commit into from Jun 22, 2021

Conversation

dfrkp
Copy link
Contributor

@dfrkp dfrkp commented Jun 22, 2021

The previous way of importing esbuild would lead the error:

node_modules/@linaria/esbuild/lib/index.js:74:29: error: [plugin: linaria] Cannot read property 'transformSync' of undefined
74 } = _esbuild.default.transformSync(rawCode, { ...esbuildOptions,

Motivation

When using linaria with esbuild as described here: https://github.com/callstack/linaria/blob/master/docs/BUNDLERS_INTEGRATION.md#esbuild one would get a failing build due to the import not working as expected. Error message:

    74 │         } = _esbuild.default.transformSync(rawCode, { ...esbuildOptions,
       ╵                              ^
    at ./node_modules/@linaria/esbuild/lib/index.js:74:30
    at callback (./node_modules/esbuild/lib/main.js:869:34)
    at handleRequest (./node_modules/esbuild/lib/main.js:652:36)
    at handleIncomingPacket (./node_modules/esbuild/lib/main.js:699:7)
    at Socket.readFromStdout (./node_modules/esbuild/lib/main.js:576:7)
    at Socket.emit (node:events:394:28)
    at addChunk (node:internal/streams/readable:312:12)
    at readableAddChunk (node:internal/streams/readable:287:9)
    at Socket.Readable.push (node:internal/streams/readable:226:10)
    at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)```

## Summary

esbuild does export `transformSync` just fine and hence it can be imported like the other interfaces.

## Test plan

To test this, you'll need a simple esbuild project. And add the build config (to build.js):

const { build } = require("esbuild");
const linaria = require("@linaria/esbuild");

const prod = process.env.NODE_ENV === "production";

build({
entryPoints: ["./src/index.tsx"],
outdir: "dist",
minify: true,
bundle: true,
plugins: [
linaria.default({
sourceMap: prod,
}),
],
}).catch(() => process.exit(1));

Now the build should work and not fail with the previously mentioned issue.

The previous way of importing esbuild would lead the error:
 > node_modules/@linaria/esbuild/lib/index.js:74:29: error: [plugin: linaria] Cannot read property 'transformSync' of undefined
    74         } = _esbuild.default.transformSync(rawCode, { ...esbuildOptions,
@callstack-bot
Copy link

Hey @dfrkp, thank you for your pull request 🤗.
The coverage report for this branch can be viewed here.

@Anber Anber merged commit a22522b into callstack:master Jun 22, 2021
@Anber
Copy link
Collaborator

Anber commented Jun 22, 2021

Thank you @dfrkp!

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

Successfully merging this pull request may close these issues.

None yet

3 participants