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

Parcel2 ignores .babelrc files in monorepos. #4120

Closed
astegmaier opened this issue Feb 13, 2020 · 0 comments · Fixed by #4132
Closed

Parcel2 ignores .babelrc files in monorepos. #4120

astegmaier opened this issue Feb 13, 2020 · 0 comments · Fixed by #4132

Comments

@astegmaier
Copy link
Contributor

astegmaier commented Feb 13, 2020

🐛 bug report

If you have a yarn-workspaces-based monorepo with custom .babelrc configuration, parcel ignores them.

This is related to #3917 - I'm filing a separate issue because there are other ways to resolve the problem reported there (for example, by adding @babel/plugin-proposal-optional-chaining to the default babel config - which IMO would be a good idea regardless of how this issue is treated).

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

I have a project configured like this:

├── package.json // {"workspaces": ["app1"]}
├── app1
│   ├── .babelrc
                  /* {
                      "plugins": ["@babel/plugin-proposal-class-properties"],
                       "presets": [[ "@babel/preset-typescript", { "isTsx": true }]]
                  } */
│   ├── index.ts // uses class properties
│   └── package.json
└── yarn.lock

🤔 Expected Behavior

The .babelrc file in the app1 project should be respected, and parcel build should succeed.

😯 Current Behavior

parcel build fails with this error:

🚨 Build failed.
@parcel/transformer-babel: /Users/Andrew/Projects/parcel2-monorepo-babel-bug/app1/src/index.ts: Missing class properties transform.
  1 | class MyClassWithProperties {
> 2 |   private message = "Hello from a class!";
    |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  3 |   sayHello() {
  4 |     console.log(this.message);
  5 |   }
SyntaxError: /Users/Andrew/Projects/parcel2-monorepo-babel-bug/app1/src/index.ts: Missing class properties transform.
  1 | class MyClassWithProperties {
> 2 |   private message = "Hello from a class!";
    |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  3 |   sayHello() {
  4 |     console.log(this.message);
  5 |   }
    at File.buildCodeFrameError (/Users/Andrew/Projects/parcel2-monorepo-babel-bug/node_modules/@babel/core/lib/transformation/file/file.js:267:12)
    at NodePath.buildCodeFrameError (/Users/Andrew/Projects/parcel2-monorepo-babel-bug/node_modules/@babel/traverse/lib/path/index.js:144:21)
    at pushBody (/Users/Andrew/Projects/parcel2-monorepo-babel-bug/node_modules/@babel/plugin-transform-classes/lib/transformClass.js:156:20)
    at buildBody (/Users/Andrew/Projects/parcel2-monorepo-babel-bug/node_modules/@babel/plugin-transform-classes/lib/transformClass.js:130:5)
    at classTransformer (/Users/Andrew/Projects/parcel2-monorepo-babel-bug/node_modules/@babel/plugin-transform-classes/lib/transformClass.js:527:5)
    at transformClass (/Users/Andrew/Projects/parcel2-monorepo-babel-bug/node_modules/@babel/plugin-transform-classes/lib/transformClass.js:563:10)
    at PluginPass.ClassExpression (/Users/Andrew/Projects/parcel2-monorepo-babel-bug/node_modules/@babel/plugin-transform-classes/lib/index.js:63:54)
    at newFn (/Users/Andrew/Projects/parcel2-monorepo-babel-bug/node_modules/@babel/traverse/lib/visitors.js:179:21)
    at NodePath._call (/Users/Andrew/Projects/parcel2-monorepo-babel-bug/node_modules/@babel/traverse/lib/path/context.js:55:20)
    at NodePath.call (/Users/Andrew/Projects/parcel2-monorepo-babel-bug/node_modules/@babel/traverse/lib/path/context.js:42:17)

Interestingly, I get the same error, even when I move the .babelrc file to the root of the monorepo.

💁 Possible Solution

As @mischnic pointed out here, these lines return a partialConfig without a `.babelrc

let partialConfig = babelCore.loadPartialConfig({
filename: config.searchPath,
cwd: path.dirname(config.searchPath),
root: options.projectRoot,
});

A possible solution would be to leverage the babelrcRoots option to pass in the package directory (in addition to the monorepo root that is already specified in the root parameter)

🔦 Context

I'm trying to set up a monorepo where the packages are built with parcel2, and I need to customize the babel configuration for some of the packages individually.

💻 Code Sample

You can reproduce the issue in master branch of this repository.

There is a working-example branch that shows the same app (with the same .babelrc) building correctly in the non-monorepo case.

🌍 Your Environment

Software Version(s)
Parcel 2.0.0-nightly.99
Node 10.16.3
Yarn 1.21.1
Operating System Mac OSX 10.15.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants