microbundle: TypeScript 3.7.x: Optional chaining and nullish coalescing is broken

The latest version of TypeScript (3.7.x) is broken if using optional chaining and nullish coalescing. It fails with the following error:

SyntaxError: /path/to/file.ts: Support for the experimental syntax 'optionalChaining' isn't currently enabled

...

Add @babel/plugin-proposal-optional-chaining (https://git.io/vb4Sk) to the 'plugins' section of your Babel config to enable transformation.

The simple fix (I think) is to update the TypeScript dependency in microbundle. However… my preference would be for microbundle to detect if I have another version of TypeScript already registered in my package.json and use that version as the default (falling back to the included dependency if required).

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 19

Commits related to this issue

Most upvoted comments

@smithki I’d assume you already are on the next version, because we didn’t have babel in 0.11.0

It should work if you add a .babelrc to your project with this content (and install the package)

{
	"plugins": [
		[
			"@babel/plugin-proposal-optional-chaining"
		]
	]
}

This bug haven’t been fixed in version 0.12.2, and a new error is thrown out:

(terser plugin) SyntaxError: Unexpected token: punc (.)

@smithki I’d assume you already are on the next version, because we didn’t have babel in 0.11.0

It should work if you add a .babelrc to your project with this content (and install the package)

{
	"plugins": [
		[
			"@babel/plugin-proposal-optional-chaining"
		]
	]
}

Doing the above worked for me in the newly released v0.12.0.

I came to the same conclusion. Shame, it was my first shot on this lib. It’s a pity it does not merge babel settings or at least, allow you to customize it or append plugins. Anyway, this should be a top priority because as for today, the statement: Typescript supported, it’s not true. Will keep an eye here for the fix. And if the fix is already there in the new version, why not publish it? @developit

Just leaving this here in case some of you have issues with the compression of typescript.

  • Add the nessesary scripts to the package.json file
"scripts": {
  "dev": "microbundle",
  "prod": "microbundle --compress",
  "watch": "microbundle watch"
},
  • Install the following packages babel packages and add them to the .babelrc file in the root of your project:
{
  "plugins": [
    "@babel/plugin-transform-typescript",
    "@babel/plugin-proposal-optional-chaining",
    "@babel/plugin-proposal-nullish-coalescing-operator",
    "@babel/plugin-proposal-object-rest-spread"
  ]
}

I mentioned that in my commment

dude I commented here for a reason. You need those 4:

"@babel/plugin-transform-typescript",
"@babel/plugin-proposal-optional-chaining",
"@babel/plugin-proposal-nullish-coalescing-operator",
"@babel/plugin-proposal-object-rest-spread"

@ForsakenHarmony yeah, I’ve managed to get what I need in microbundle@next, but unfortunately for the use-case I’m after, the rest of my team is wary of pre-release NPM packages. When will 0.12.x be released mainstream? It would be a lifesaver.