Skip to content

Babel 7 "SyntaxError: Unexpected token import" in lerna environment #7208

@Raigen

Description

@Raigen

We use lerna to seperate concernes into multiple packages. One of them is depending on two others to combine them in the final build. For production we build them independently and then put the dependencies into the node_modules directory of the first package.
In development we do nothing special because babel-node from the first package seems to take care of the import statements also from the other packages.
After I updated to babel 7 for testing purpose babel does not transform the other packages anymore.
I created two repositories with a minimal reproducer of the environment, one with babel6 where the import works and one with babel 7 dependencies where it does not work anymore.

Using @babel/register here https://github.com/Raigen/babel7-tmp/blob/master/packages/pck2/index.js#L4 does not work either.

I am out of ideas right now. I expect this to work because babel itself is a monorepo with lerna and import-dependencies inside ./packages. But I can not get it to work even in the simple reproducer repos I created.

Input Code

https://github.com/Raigen/babel6-tmp
https://github.com/Raigen/babel7-tmp

Expected Behavior

https://github.com/Raigen/babel6-tmp

Current Behavior

https://github.com/Raigen/babel7-tmp

Context

We plan to refactor one of our packages with typescript. For this purpose we need to figure out how the development environment can work with one package on typescript and the other packages still on babel. And the best idea until now is to keep babel everywhere and move to babel 7 with the typescript preset. This does work for all packages running independently and in the build, but not when I try to run the one package that imports from the others.
Also we of course want to keep our dependencies updated, so even without typescript we would want to upgrade to babel 7 when it is final.

Your Environment

software version(s)
Babel 7.0.0-beta.37
node 8.9.4
npm 5.6.0
Operating System tested on Windows 10 and Mac OS High Sierra

Metadata

Metadata

Assignees

No one assigned

    Labels

    i: questionoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions