0

I am using Parcel version 2 to build my JavaScript app, and one of the modules in node_modules is CommonJS but uses "let" and "const" keywords, so I need to transpile it so it is compatible with IE 11, which we are still supporting for a few more months.

By default parceljs does not transpile code in node_modules, somehow expecting that package developers will know which browsers their users are targeting and provide ready-to-use code. I have read that parcel 2 is honors babel configuration files, and I have created one, but that alone does not tell it to transpile the code from node_modules. I do not need to transpile all the node_modules code, but apparently just the one module. Here is my .babelrc.json, which it seems to be looking at because I get some warnings about the use of parcel-env which I build:

{
  "presets": [
    ["@babel/preset-env", {
      "targets": "IE 11, last 2 versions"
    }]
  ]
}

What other configuration am I missing to get to transpile either all of node_modules or a particular module?

Note: Other posts I have found around this topic were for version 1 of Parcel, and there were hints that there would be better options in version 2.

Paul Lynch
  • 1,297
  • 13
  • 20
  • 1
    I don't have the complete answer yet, but three tips: (1) parcel will transpile your source code using `swc` by default if you don't specify a babel config (see [docs](https://parceljs.org/languages/javascript/#default-presets)) (2) if you want to target older browsers, all you need is a `browserlists` entry in your `package.json` ([docs](https://parceljs.org/features/targets/#package.json%23browserslist)) and (3) transpiling `node_modules` code isn't supported (yet), but you might be able to hack this with [a patch](https://github.com/parcel-bundler/parcel/issues/1655#issuecomment-775890192) – Andrew Stegmaier Dec 01 '21 at 17:37
  • That patch got rid of the "let" statements in that module, but now I am getting other errors, like "Symbol" being undefined (which seems to be coming from code added by parcel). Anyway, I think this sovles the question I posted. – Paul Lynch Dec 01 '21 at 21:01
  • It looks like the parcel team is in the process of changing behavior so that `node_modules` code is transpiled by default - see this PR: https://github.com/parcel-bundler/parcel/pull/7399 – Andrew Stegmaier Dec 06 '21 at 16:03

1 Answers1

0

Include this "browserslist": "> 0.5%, last 2 versions, not dead", right after name in your package.jason. Reason being that Parcel 2 no longer does any transpilation by default. Visit parcel website https://parceljs.org/getting-started/migration/ for more information.