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

ES5 transpilation on typescript #2436

Closed
Banou26 opened this issue Dec 18, 2018 · 5 comments
Closed

ES5 transpilation on typescript #2436

Banou26 opened this issue Dec 18, 2018 · 5 comments
Labels

Comments

@Banou26
Copy link
Contributor

Banou26 commented Dec 18, 2018

🐛 bug report

Parcel ignores engines.node and still transpile the code with babel

🎛 Configuration (.babelrc, package.json, cli command)

package.json

{
  "name": "parcel-node-babel",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "parcel-bundler": "^1.11.0"
  },
  "scripts": {
    "build": "parcel --target node src/index.ts",
    "start": "node dist/index.js"
  },
  "devDependencies": {
    "typescript": "^3.2.2"
  },
  "engines": {
    "node": ">= 8.0.0"
  }
}

🤔 Expected Behavior

Parcel respect engines.node for node just like it respect browserslist for the browser target

😯 Current Behavior

import JSPackager from 'parcel-bundler/src/packagers/JSPackager'
class Foo extends JSPackager{}
new Foo()

The source code is transpiled to ES5 which causes the Foo class to be transpiled to a function and throw Class constructor JSPackager cannot be invoked without 'new'

I think it's related to #839 but in their case, setting browserslist to "last 1 Chrome versions" fix the problem, but since in my case the target is node, browserlist is replaced by engines.node which doesn't work.

💻 Code Sample

https://github.com/Banou26/parcel-node-babel

🌍 Your Environment

Software Version(s)
Parcel 1.11.3
Node 11.5.0
npm/Yarn
Operating System
@Banou26
Copy link
Contributor Author

Banou26 commented Dec 21, 2018

After some tests, it appears that the code is always transpiled to ES5 when the source is a typescript file , if the file is javascript, the code is properly transpiled using the browserslist and engines.node

@Banou26 Banou26 changed the title Babel transpilation on node target ES5 transpilation on typescript Dec 21, 2018
@Banou26
Copy link
Contributor Author

Banou26 commented Dec 21, 2018

After some more tinkering i finally found the solution to prevent typescript from transpiling to es5
tsconfig.json

{
  "compilerOptions": {
    "target": "esnext"
  }
}

@Banou26 Banou26 closed this as completed Dec 21, 2018
@ViktoriaShelestenko
Copy link

After some more tinkering i finally found the solution to prevent typescript from transpiling to es5
tsconfig.json

{
  "compilerOptions": {
    "target": "esnext"
  }
}

THANK YOU! You helped a lot!

@mischnic mischnic reopened this Jan 12, 2019
@mischnic
Copy link
Member

We should consider applying browserslist or engines.node to typescript (maybe only if that value isn't already set in tsconfig.json).

@mischnic
Copy link
Member

See #860

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants