parcel-bundler / parcel

The zero configuration build tool for the web. 📦🚀
https://parceljs.org
MIT License
43.48k stars 2.27k forks source link

Parcel 2 doesn't seem to respect targets in yarn workspaces #4287

Open huw opened 4 years ago

huw commented 4 years ago

🐛 bug report

When I try to run parcel build on an index.js file inside a Yarn workspace, Parcel 2 doesn't respect the main field, or any other target configuration, and simply builds the default dist/index.js target.

I am not sure if I am simply misunderstanding Parcel 2's configuration.

🎛 Configuration

package.json (Root)

{
  "name": "parcel-workspace-test",
  "version": "1.0.0",
  "license": "MIT",
  "private": true,
  "workspaces": [
    "package"
  ]
}

package/package.json

{
  "name": "package",
  "version": "1.0.0",
  "license": "MIT",
  "private": true,
  "devDependencies": {
    "parcel": "^2.0.0-nightly.140"
  },
  "main": "dist/main.js"
}

package/src/index.js

/* test comment */
module.exports = 2;

🤔 Expected Behavior

When running yarn workspace package parcel build src/index.js, Parcel should produce a dist/main.js file.

😯 Current Behavior

Parcel produces a dist/index.js file.

🔦 Context

This is a minimum working example, so hopefully no more context is needed.

💻 Code Sample

Git repo

🌍 Your Environment

Software Version(s)
Parcel ^2.0.0-nightly.140
Node 12.15.0
Yarn 1.22.0
Operating System macOS 10.15.3
mischnic commented 4 years ago

This is caused "intentionally" by https://github.com/parcel-bundler/parcel/pull/4098.

But we need to fix this anyway.

huw commented 4 years ago

Okay! I got it working by adding a source field to my package.json and pointing Parcel at the directory. This works great for now, although it could be useful to be able to point the CLI directly to an entry and have it compile against the nearest package.json's targets.

I'm not sure about @devongovett's rationale in #4098, but it seems to me like in a monorepo it's more common to want to compile against a child package.json's targets and that should be the default. But that's my 0.2c.