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 adapter-node build in presence of tsconfig.json #1675

Merged
merged 2 commits into from
Jun 14, 2021

Conversation

Conduitry
Copy link
Member

Fixes #1667 in a way that (as far as I can tell) does not break compatibility with Node 12.

In Kit apps written in TypeScript, esbuild was seeing the tsconfig.json in the user's app and the target in there was being used since the call to esbuild.build() did not explicitly specify one. This was a problem because the starter app uses es2019, which does not support import.meta.url, and so the references to this (including the ones in the code introduced by the adapter) were being replaced with undefined.

We don't want to tell the adapter to bundle for target: 'es2020' because that would then mean we wouldn't be transpiling features not supported by Node 12. Luckily, esbuild lets us do target: 'node12', which transpiles specifically the features not supported in Node 12. This lets us use ?. (which will get transpiled) and also use import.meta.url (which is left as-is since it is supported natively in Node 12, even though it doesn't support all of ES2020).

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpx changeset and following the prompts

Without an explicit target value, esbuild will pick up the version from
tsconfig.json, if present. This breaks the build if that specifies a
target of es2019, which does not support import.meta.
@joidegn
Copy link

joidegn commented Jun 12, 2021

I was also facing issue #1667 and can confirm that this PR fixes the issue for me.

I have "target": "es2018" in my tsconfig.json

@Conduitry Conduitry merged commit 53f3322 into sveltejs:master Jun 14, 2021
@Conduitry Conduitry deleted the gh-1667 branch June 14, 2021 14:35
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.

@sveltejs/adapter-node failure due to ES version
2 participants