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

tsconfig’s paths aren’t prioritized over node_modules when a custom tsconfig is used #278

Closed
iamakulov opened this issue Jul 20, 2020 · 1 comment

Comments

@iamakulov
Copy link

Hey,

I stumbled upon an issue with a custom tsconfig.json.

When you use a custom tsconfig, ESBuild seems to prioritize node_modules over tsconfig.json’s paths (which means you can’t overwrite any installed dependencies). This is not an issue when the tsconfig.json file is automatically detected.

Repro

1. Create the test project:

yarn init -y
yarn add esbuild linaria

# tsconfig.json
echo '{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "linaria": ["./linaria-mock.ts"]
    }
  }
}' > tsconfig.json

# index.ts
echo 'import { css } from "linaria";

const styles = css`
  color: red;
`;

console.log(styles);' > index.ts

# linaria-mock.ts
echo 'export function css() {
  return 5;
}' > linaria-mock.ts

2. Run ESBuild with the --tsconfig flag:

yarn esbuild --bundle index.ts --outfile=out.js --platform=node --tsconfig=tsconfig.json

3. Try to run the generated bundle:

node out.js

Expected result

The linaria package should’ve been replaced with ./linaria-mock.ts. So the generated bundle should print 5:

$ node out.js
5

Actual result

The linaria package is used as-is, despite the paths section in tsconfig. Therefore, the generated bundle throws a Linaria error:

$ node out.js
/tmp/esbuild-bug-test/out.js:32
    throw new Error('Using the "css" tag in runtime is not supported. Make sure you have set up the Babel plugin correctly.');
    ^

Error: Using the "css" tag in runtime is not supported. Make sure you have set up the Babel plugin correctly.
    at Object.css2 (/tmp/esbuild-bug-test/out.js:32:11)
    at Object.<anonymous> (/tmp/esbuild-bug-test/out.js:58:27)
    at Module._compile (internal/modules/cjs/loader.js:1138:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
    at Module.load (internal/modules/cjs/loader.js:986:32)
    at Function.Module._load (internal/modules/cjs/loader.js:879:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47

Further notes

  • The issue disappears if you use an automatically inferred tsconfig.json file:

    # Note: no --tsconfig=tsconfig.json flag
    $ yarn esbuild --bundle index.ts --outfile=out.js --platform=node
    $ node out.js
    5
  • The issue disappears if you remove the linaria dependency:

    $ yarn remove linaria
    $ yarn esbuild --bundle index.ts --outfile=out.js --platform=node --tsconfig=tsconfig.json
    $ node out.js
    5

    In this case, the overwrite happens as expected.

@evanw evanw closed this as completed in 3e027f6 Jul 25, 2020
@evanw
Copy link
Owner

evanw commented Jul 25, 2020

Thanks for the report. This should be fixed as of esbuild version 0.6.6.

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

2 participants