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

create-svelte generates a CJS output #11086

Closed
hyunbinseo opened this issue Nov 20, 2023 · 3 comments · Fixed by #11092
Closed

create-svelte generates a CJS output #11086

hyunbinseo opened this issue Nov 20, 2023 · 3 comments · Fixed by #11092
Labels
bug Something isn't working p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc. pkg:svelte-package Issues related to svelte-package

Comments

@hyunbinseo
Copy link
Contributor

hyunbinseo commented Nov 20, 2023

Describe the bug

The default library template generates a CJS output.

// dist/index.js

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// Reexport your entry components here

This issue started from create-svelte version 5.3.0.

Reproduction

npm create svelte@latest
create-svelte version 5.3.1

┌  Welcome to SvelteKit!
│
◇  Where should we create your project?
│  [email protected]
│
◇  Which Svelte app template?
│  Library project
│
◇  Add type checking with TypeScript?
│  Yes, using TypeScript syntax
│
◇  Select additional options (use arrow keys/space bar)
│  Add ESLint for code linting, Add Prettier for code formatting
│
└  Your project is ready!
npm i && npm run package

Logs

create-svelte-5.3.1 lint results:
Warnings:
1. pkg.exports["."].svelte is ./dist/index.js and is written in CJS, but is interpreted as ESM. Consider using the .cjs extension, e.g. ./dist/index.cjs

create-svelte-5.3.0 lint results:
Warnings:
1. pkg.exports["."].svelte is ./dist/index.js and is written in CJS, but is interpreted as ESM. Consider using the .cjs extension, e.g. ./dist/index.cjs

create-svelte-5.2.0 lint results:
All good!

System Info

System:
  OS: macOS 14.0
  CPU: (10) arm64 Apple M1 Pro
  Memory: 155.33 MB / 16.00 GB
  Shell: 5.9 - /bin/zsh
Binaries:
  Node: 20.9.0 - ~/Library/pnpm/node
  npm: 10.1.0 - ~/Library/pnpm/npm
  pnpm: 8.10.5 - ~/Library/pnpm/pnpm
Browsers:
  Chrome: 119.0.6045.123
  Edge: 119.0.2151.72
  Safari: 17.0
npmPackages:
  @sveltejs/adapter-auto: ^2.0.0 => 2.1.1 
  @sveltejs/kit: ^1.27.4 => 1.27.6 
  @sveltejs/package: ^2.0.0 => 2.2.2 
  svelte: ^4.0.5 => 4.2.5 
  vite: ^4.4.2 => 4.5.0

Severity

annoyance

Additional Information

No response

@hyunbinseo
Copy link
Contributor Author

Removing this line in tsconfig.json generates an ESM output.

- "module": "NodeNext",

However, removing the above line causes this TypeScript error.

Option 'module' must be set to 'NodeNext' when option 'moduleResolution' is set to 'NodeNext'.

Reference #11029

@benmccann
Copy link
Member

However, removing the above line causes this TypeScript error.
Option 'module' must be set to 'NodeNext' when option 'moduleResolution' is set to 'NodeNext'.

It doesn't cause the error for me. What command were you running to see that error message or is there anything else I might have to do to reproduce it?

@benmccann benmccann added bug Something isn't working p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc. labels Nov 20, 2023
@hyunbinseo
Copy link
Contributor Author

The reproduction steps are same as before. #11023

Try pnpm check and repeatedly close and open tsconfig.json file in VS Code.

dummdidumm added a commit that referenced this issue Nov 21, 2023
transpileModule treats NodeNext as CommonJS because it doesn't read the package.json. Therefore we need to override it. Also see microsoft/TypeScript#53022 (the filename workaround doesn't work).
Fixes #11086
dummdidumm added a commit to sveltejs/svelte-preprocess that referenced this issue Nov 21, 2023
transpileModule treats NodeNext as CommonJS because it doesn't read the package.json. Also see microsoft/TypeScript#53022 (the filename workaround doesn't work). Related to sveltejs/kit#11086
@benmccann benmccann added pkg:svelte-package Issues related to svelte-package and removed pkg:create-svelte labels Nov 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc. pkg:svelte-package Issues related to svelte-package
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants