parcel-bundler / parcel

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

Path Aliases Not Working on node targets #9519

Open chin2km opened 9 months ago

chin2km commented 9 months ago

🐛 bug report

After updating to parcel@2.11.0 (from v2.8.3), the alias config in package.json stopped working on the node target.

🎛 Configuration

Created a very lean reproduction with just the alias config in package.json

Repo: https://github.com/chin2km/parcel-bug-reproduction

{
  "targets": {
    "server": {
      "context": "node",
      "outputFormat": "esmodule",
      "source": "./src/server-entry.tsx",
      "distDir": "./dist/server"
    }
  },
  "alias": {
    "lodash": "./src/patch/lodash.ts"
  },
}

🤔 Expected Behavior

The path alias should work on all targets (node and browser)

😯 Current Behavior

Path alias only works on browser target. Node target throws runtime error.

TypeError: (0 , _lodash.xxx) is not a function

💁 Possible Solution -> 🤷🏻

🔦 Context

Our company (a popular Fashion MarketPlace in the EU) is trying to migrate away from Webpack. We have been beta testing Parcel as a bundler in dev mode and it has been a success. But now we are trying to get out of this beta phase and go all in on Parcel.

💻 Code Sample

Repo: https://github.com/chin2km/parcel-bug-reproduction

🌍 Your Environment

Software Version(s)
Parcel 2.11.0
Node 20.0.0
Yarn 1
Operating System MacOs
hanbyul-here commented 4 months ago

I also encountered the alias problem when building a library when I bumped the minor version of Parcel from 2.7 to 2.12. I tested with several minor versions of Parcel, and this problem started appearing in v2.9.

In case this helps anybody, I worked around this problem by putting the alias resolver when the build target is library. But it will be great to see aliases working for all the targets.