Parcel 2: TypeScript automatic zero configuration not type checking or reading tsconfig.json
See original GitHub issueI’ve been following #1378 for a long time, and I’m thrilled to see Parcel 2 taking on better first-class support for TypeScript. There’s currently some problems with Parcel 2 out of the box, and I didn’t see any threads tracking this, so I’m making an issue.
🐛 bug report
In 2.0.0-alpha.3.2, given a very basic TypeScript project, there are three issues:
- the
typescript
package is not automatically installed - settings in
tsconfig.json
are completely ignored - typescript errors are silently ignored and compiled anyway
🎛 Configuration (.babelrc, package.json, cli command)
Here’s all of the files:
package.json
created from two commands:yarn init -y
yarn install -D parcel@v2
index.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title>My First Parcel App</title> <script src="index.ts"></script> </head> <body> <h1>Hello, World!</h1> </body> </html>
index.ts
console.log("Hello, von Nuemann!") const failMe: BadType = 5; // this should fail, but it compiles
- optionally, I added a junk
tsconfig.json
to test, and it’s obviously being ignored because parcel still compiles:{ ALDIFJ SLDIFJ :LEIRJ LWEIJR; }}}}} "compilerOptions": {
🤔 Expected Behavior
As part of parcels “zero configuration”, parcel automatically detects TypeScript and configures the project to correctly use TypeScript.
- TypeScript compilation or validation should fail by default when there are type errors
typescript
package should be installed automaticallytsconfig.json
should be read and used by whatever is compiling it, if it exists
😯 Current Behavior
- the
typescript
package is not automatically installed - settings in
tsconfig.json
are completely ignored - typescript errors are silently ignored and compiled anyway
💁 Possible Solution
I’m guessing one of these two potential solutions:
- The current default
transformer-babel
is correctly configured to behave as expected with TypeScript, extending from #3083 typescript
and@parcel/transformer-typescript(-tsc?)
is automatically installed when Parcel 2 detects a.ts
file.
Either one is fine, I think, as long as the TypeScript compilation actually behaves like TypeScript by default!
🔦 Context
- Seems to have started in this PR that defaults to
babel
for TypeScript: https://github.com/parcel-bundler/parcel/pull/3083 - Type checking seems to have been merged, but it’s not happening: https://github.com/parcel-bundler/parcel/pull/3232
💻 Code Sample
See files above
🌍 Your Environment
Software | Version(s) |
---|---|
Parcel | 2.0.0-alpha.3.2 |
Node | v10.15.3 |
npm/Yarn | 1.21.1 |
Operating System | Mac 10.14.6 |
Issue Analytics
- State:
- Created 4 years ago
- Reactions:121
- Comments:84 (32 by maintainers)
Top Results From Across the Web
TypeScript
A tsconfig.json file can be used to configure some aspects of the transpilation ... The TSC transformer also does not perform any type...
Read more >Parcel 2 alpha TypeScript RFC
No type checking, no tsconfig.json, etc. ... The current Parcel 2 alpha's default "zero configuration" for TypeScript is to use babel to ...
Read more >Zero Configure your React-Typescript App With Parcel
Luckily, there is a solution. Parcel offers us a zero-configuration setup. That means, there is no configuration file for Parcel, unlike we ...
Read more >You may not need a bundler for your NPM library
Note: We do not need to explicitly say where the typescript types are with "types" in package.json , many starter packs do this...
Read more >TSDX: Introduction
TSDX is a zero-config CLI that helps you develop, test, and publish modern TypeScript packages with ease--so you can focus on your awesome...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m quite confused by that position. If the official stance is that external tools should be used for handling compilation errors, why does Parcel report errors for other compilers, like sass? Sass is a superset of CSS with a compiler, much like TypeScript is a superset of JavaScript with a compiler. It seems like you’re looking at TypeScript as if it’s a linter instead of a separate language with separate compilation and configuration needs.
I propose that TypeScript is treated as a first-class zero-configuration part of Parcel’s bundler, using the real Microsoft TypeScript compiler by default, with full type checking in the bundling process. No external tools required, it’s just drop in a
ts
file and the appropriate libraries are added and run.If people want to use babel for whatever reason, that could be configured in
parcelrc
. Not every project that uses TypeScript will want to use Babel, especially because Babel doesn’t support the full TypeScript language spec.Thank you for opening this up for dialogue so the community can comment.
Our opinion was that your IDE should catch typing errors when developing and on deploy using a CI/CD service it should be a step before even starting up anything (including Parcel) to speedup the process, similar to how you’d do linting. Typing fails, don’t run build/tests/…
I’ve also been using typescript for a couple years and have never had the need to have parcel throw validation errors the IDE integration works fine for most cases.
In my opinion this should never be considered a bug, it’s just a different opinion. The default might change though, especially as we have full freedom as it’s still alpha.
I didn’t know vue couldn’t be typechecked using tsc. This is pretty convincing to change the default… although the spam in dev mode is pretty annoying but probably the point of having types I guess.
On a positive note the validations only run after Parcel fully completed so you never have the annoying issue that you can’t look at a change without fixing the types. It does however return an error in production mode so a properly configured CI/CD pipeline would not deploy…
I’ll flag this as an RFC, seems more fitting than question or bug. Would be cool to do a poll on this or something at some point.