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

Babel 7 monorepo issue #8945

Open
judikdavid opened this Issue Oct 30, 2018 · 7 comments

Comments

Projects
None yet
6 participants
@judikdavid

judikdavid commented Oct 30, 2018

v7 Regression

Describe the regression
I want to run build/test cli command from packages as well, not just from the project root.
If I run npx babel-node index.js in my project root, everything works as expected.
But if I run npx babel-node index.js inside packages/packA, I get the following error:

/Users/djudik/repos/babel-7/packages/packB/index.js:3
export default (a: number, b: number) => {
^^^^^^

SyntaxError: Unexpected token export

I assume that packB file does not get compiled when I want to use it from packA, not from the project root.

Input Code
https://github.com/judikdavid/babel-7

Babel Configuration (.babelrc, package.json, cli command)
https://github.com/judikdavid/babel-7/blob/master/babel.config.js

Expected behavior/code
I should be able to use babel from any packages folder and it should use the root babel.config.js config.

Environment

  • Babel version(s): "@babel/core": "^7.1.2"
  • Node/npm version: Node 10.11.0/npm 6.4.1
  • OS: OSX 10.14]
  • Monorepo: yes
  • How you are using Babel: cli
@babel-bot

This comment has been minimized.

Collaborator

babel-bot commented Oct 30, 2018

Hey @judikdavid! 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

This comment has been minimized.

Member

nicolo-ribaudo commented Oct 30, 2018

It is the expected behavior: Babel only searches for babel.config.js in the current directory. This behavior can be changed using the root and rootMode programmatic options (https://babeljs.io/docs/en/options#root), or using babel-node --config-file ../../babel.config.js

@judikdavid

This comment has been minimized.

judikdavid commented Oct 30, 2018

Thank you for your answer. However if I use npx babel-node --config-file ../../babel.config.js index.js in packA folder, I still get the same error.

@rwieruch

This comment has been minimized.

rwieruch commented Nov 12, 2018

I find it super difficult to find a minimal working example project on this topic :)

@sibelius

This comment has been minimized.

sibelius commented Nov 13, 2018

@nicolo-ribaudo

this is my monorepo structure, using yarn workspaces

packages
- api
---- src
- graphql
---- src
- common
---- src

all packages have a main pointing to src/index.js on package.json

I wan to import functions from common package inside api package

sample code:

import { myFn } from 'common'

use have a babel.config.js on root, it has the same configs of all packages, and we also tried to add babelrcRoots to try to fix some issues:

const { workspaces = [] } = require('./package.json');

module.exports = {
  babelrcRoots: [
    '.',
    ...(workspaces.packages || workspaces),
  ],
  // presets and plugins here

We are getting the folowing error:

repo/packages/common/src/index.js
import  myFn from './myFn'';
       ^^^^^^^^^^^^^^^^

SyntaxError: Unexpected identifier

so it looks like babel-node is not transpiling common package

we tried to run the api like this:

./node_modules/.bin/babel-node ./packages/api/src/index.js

but this command broke the imports

then we used lerna run, and it worked well:

scripts of package.json (root)

"start:api": "lerna run start --scope api --stream",

scripts on api package.json (api)

"start": "babel-node src/index.js",

am I missing anything?, should I have a include on babel.config.js or use --ignore when calling babel-node?

@adityak74

This comment has been minimized.

adityak74 commented Nov 16, 2018

Using --ignore=' ' worked for me with my monorepo setup.

@adityak74

This comment has been minimized.

adityak74 commented Nov 16, 2018

I got this working without the --ignore flag if you want to have a look at: https://github.com/adityak74/babel7-import-example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment