question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Babel 7 monorepo issue

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:22 (6 by maintainers)

github_iconTop GitHub Comments

9reactions
rwieruchcommented, Nov 12, 2018

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

3reactions
sibeliuscommented, 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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Upgrade to Babel 7
Babel has had issues previously with handling node_modules , symlinks, and monorepos. We've made some changes to account for this: Babel will stop...
Read more >
javascript - Trying to configure Babel in a monorepo project
This is probably caused by react-native-modal not transpiling class property syntax. And, by default, node_modules will not be transpiled.
Read more >
Monorepo setup with Lerna, TypeScript, Babel 7 and other
We could avoid all issues relate to code formatting with prettier . It will automatically format our code according to predefined standards.
Read more >
@monorepo-template/jest-preset - npm
This error occurs when babel-jest and jest have different major versions. Resolve this by either upgrading one (preferred) or downgrading the ...
Read more >
How to transpile node_modules with babel and webpack in a ...
How to transpile node_modules with babel and webpack in a monorepo. Somto — August 08, 2019 — Coding — 7 min. read. ℹ️...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found