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

svelte-kit sync outputs "If bundling, conditions should include development or production...." #13238

Closed
thebjorn opened this issue Dec 24, 2024 · 3 comments · Fixed by #13244

Comments

@thebjorn
Copy link

Describe the bug

The following message is printed (multiple times if using a monorepo):

If bundling, conditions should include development or production. If not bundling, conditions or NODE_ENV should include development or production. See https://www.npmjs.com/package/esm-env for tips on setting conditions in popular bundlers and runtimes.

I've read the printed link several times, but I can't figure out what it is telling me I need to do (at least anything I've done has not removed the message) - in any case, sv really ought to create code that doesn't produce warnings ;-)

Reproduction

Normally you get this when running pnpm build (or turbo build in my case) in CI, but you can very simply reproduce it like so:

> sv create sk-sync-bug
┌  Welcome to the Svelte CLI! (v0.6.9)
│
◇  Which template would you like?
│  Svelte library
│
◇  Add type checking with Typescript?
│  Yes, using Typescript syntax
│
◆  Project created
│
◇  What would you like to add to your project? (use arrow keys / space bar)
│  none
│
◇  Which package manager do you want to install dependencies with?
│  pnpm
│
◆  Successfully installed dependencies
│
◇  Project next steps ─────────────────────────────────────────────────────╮
│                                                                          │
│  1: cd sk-sync-bug                                                       │
│  2: git init && git add -A && git commit -m "Initial commit" (optional)  │
│  3: pnpm dev --open                                                      │
│                                                                          │
│  To close the dev server, hit Ctrl-C                                     │
│                                                                          │
│  Stuck? Visit us at https://svelte.dev/chat                              │
│                                                                          │
├──────────────────────────────────────────────────────────────────────────╯
│
└  You're all set!

> cd sk-sync-bug
sk-sync-bug> pnpm up *
....
sk-sync-bug> pnpm i
...
sk-sync-bug> pnpm svelte-kit sync                                                                         
If bundling, conditions should include development or production. If not bundling, conditions or NODE_ENV should include development or production. See https://www.npmjs.com/package/esm-env for tips on setting conditions in popular bundlers and runtimes.

A repo with the above is available at: https://github.com/thebjorn/sk-sync-bug

Logs

see above

System Info

System:
    OS: Windows 11 10.0.22631
    CPU: (48) x64 AMD Ryzen Threadripper 3960X 24-Core Processor
    Memory: 25.88 GB / 63.88 GB
  Binaries:
    Node: 22.12.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.22 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 10.9.2 - C:\Program Files\nodejs\npm.CMD
    pnpm: 9.15.1 - ~\AppData\Local\pnpm\pnpm.CMD
    bun: 1.1.41 - ~\AppData\Roaming\npm\bun.CMD
  Browsers:
    Edge: Chromium (127.0.2651.74)
    Internet Explorer: 11.0.22621.3527
  npmPackages:
    @sveltejs/adapter-auto: ^3.3.1 => 3.3.1
    @sveltejs/kit: ^2.15.0 => 2.15.0
    @sveltejs/package: ^2.3.7 => 2.3.7
    @sveltejs/vite-plugin-svelte: ^5.0.3 => 5.0.3
    svelte: ^5.15.0 => 5.15.0
    vite: ^6.0.5 => 6.0.5

Severity

annoyance

Additional Information

No response

@thebjorn
Copy link
Author

I figured out I can set the NODE_ENV environment variable before running svelte-kit sync:

		"package": "set NODE_ENV=production && svelte-kit sync && svelte-package && publint",

but that will either work in dev/windows or ci/prod/linux. At least I don't know of a common way to specify environment variable values that will work for both platforms.

@eltigerchino
Copy link
Member

eltigerchino commented Dec 26, 2024

Related to benmccann/esm-env#13 . This happens whenever svelte-check is run, even on non-library projects.

Perhaps @benmccann can shed some light on this warning and the correct action here (do we need to change SvelteKit, the create-svelte template, etc.)

@benmccann
Copy link
Member

It's sync that's creating the error (not svelte-check). I don't know why/where the SvelteKit CLI is loading esm-env and if it should be. If it's doing so unnecessarily, then stopping it from doing that would be the best solution.

If you bundle an app with Vite or Rollup you won't see that message. But since the CLI is unbundled, esm-env is warning that the code is being run without knowing if it's in development or production mode, so it doesn't know if it should show dev-time warnings. Perhaps we should set process.env.NODE_ENV=production inside @sveltejs/kit/src/cli.js if it is not defined - or perhaps we should set development. It's hard to know exactly without knowing where it's being used and what for

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 a pull request may close this issue.

3 participants