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

7.0.0-beta.46 regression: "Unexpected token" with TypeScript #7791

Closed
deepsweet opened this issue Apr 24, 2018 · 8 comments
Closed

7.0.0-beta.46 regression: "Unexpected token" with TypeScript #7791

deepsweet opened this issue Apr 24, 2018 · 8 comments
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@deepsweet
Copy link

Bug report.

Input Code

import { resolve } from 'path'

type Options = {
  file?: string,
  preset?: string
}

Babel/Babylon Configuration (.babelrc, package.json, cli command)

{
  "presets": [
    [
      "@babel/preset-env",
      {
        "targets": {
          "node": "current"
        },
        "modules": false
      }
    ],
    "@babel/preset-typescript"
  ],
  "plugins": [
    "@babel/plugin-proposal-object-rest-spread",
    "@babel/plugin-syntax-dynamic-import"
  ]
}

Expected Behavior

No errors.

Current Behavior

Unexpected token, expected ";" (3:5)

  1 | import { resolve } from 'path'
  2 |
> 3 | type Options = {
    |      ^

How to reproduce: clone https://github.com/deepsweet/start, yarn, yarn upgrade, yarn start

Possible Solution

Works fine with beta.44.

Context

Your Environment

software version(s)
Babel 7.0.0-beta.46
node 8.11.1
npm 5.8.0
Operating System macOS
@babel-bot
Copy link
Collaborator

Hey @deepsweet! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.

@nicolo-ribaudo
Copy link
Member

We changed the .babelrc/package.json#babel search to stop at package.json files. If you use a monorepo, you need to create a babel.config.js file in your root and put your configuration there.

@deepsweet
Copy link
Author

deepsweet commented Apr 24, 2018

http://www.nooooooooooooooo.com/

What's the reason behind this huge change?

@deepsweet
Copy link
Author

I mean I do know the story regarding babel.config.js, I just didn't expect that package.json config resolution is going to be affected that way.

@MilosRasic
Copy link

Ended up here looking for reasons for the same problem but with multirepo setup where npm packages contain raw es6 and @babel/register used for tests is explicitly told to transpile them. Adding babelrcRoots: true to the config for babelRegister call fixed the problem.

@deepsweet you could try adding it to your @babel/register options in package.json

@deepsweet
Copy link
Author

unfortunately only babel.config.js file works in my case, babelrcRoots: true looks promising but it doesn't help.

@hzoo
Copy link
Member

hzoo commented Apr 24, 2018

FYI the PR was #7358. This is an issue we've been trying to look into since November; a PR was posted a while ago and we've reached out to many folks in the community for feedback. Didn't have any better suggestions and we agreed to go with this solution. You can read the description to get a idea of the changes. We've had to make the same changes for babel itself since it is also a monorepo, #7784. This wasn't a change we just randomly did.

@deepsweet
Copy link
Author

It's a bit confusing, but I almost figured it out – here I have another monorepo with package.json#babel which is working just fine.

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jul 24, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jul 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

5 participants