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

Reverting to undefined loader breaks library depending on this behavior #90

Closed
joyheron opened this issue Jan 3, 2022 · 3 comments · May be fixed by paaschdigital/playwright#3 or organich/playwright#5
Labels

Comments

@joyheron
Copy link

joyheron commented Jan 3, 2022

Hi,

I am working on a project which has pirates as a transitive dependency, and now get an exception after upgrading from 4.0.1 to 4.0.3. The commit which seems to cause my problems seems to be this one:

cf74daf

As far as I can tell, the error occurs in this library here which uses @babel/register which uses pirates as a dependency: https://github.com/complate/complate-fractal/blob/master/src/transpiler.js#L6

The code that I am having problems with is as follows:

require('@babel/register')({
  extensions: ['.jsx'],
  ignore: [], // activates transpilation for third-party modules
  presets: ['@babel/preset-env'],
  plugins: [
    ['@babel/plugin-transform-react-jsx', {
      pragma: 'createElement',
      pragmaFrag: 'Fragment'
    }]
  ]
})
// activate support for ES6 import/export syntax (required for non-JSX ES6 modules, notably complate-stream)
require = require('esm')(module) // eslint-disable-line no-global-assign

I believe this worked previously because for extensions which are not explicitly specified here, the default used to be to use the default JS loader. As far as I can tell, the require('esm')(module) line now throws an error if there are any imports on the path which do not use a known extension. If I pass in ['.jsx', '.mjs', '.cjs'] as extensions in L6 of that file, then the error no longer occurs for my project.

I am willing to make a PR to the complate-fractal project to change that line there, but it feels like the wrong place to correct it because I actually would prefer to use the JavaScript loader to load .cjs and .mjs files. Here it is also not possible to leave off the extensions because then babel tries to register the JSX loader for all the .js files as well and that causes problems when loading some dependencies (e.g. prettier). For me, specifying the .cjs and .mjs in the extension list here also feels like a smell -- currently the code will work if I modify that, but if in the future my transitive dependencies are updated to include imports from different file extensions, then there is a likelihood that this will break in the code again.

Here is my demo project which currently throws an error when running: https://github.com/joyheron/complate-fractal-demo
I've created a branch to demonstrate that downgrading the pirates version to 4.0.1 solves the issue: https://github.com/joyheron/complate-fractal-demo/tree/complate-fractal-works-with-pirates-4.0.1

@danez
Copy link
Owner

danez commented Jan 24, 2022

Sorry for the late reply, I'm checking this now.

@danez danez closed this as completed in 4e1b015 Jan 24, 2022
@github-actions
Copy link

🎉 This issue has been resolved in version 4.0.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

@joyheron
Copy link
Author

Thank you for the fix! I've done an update and verified that my project works again with pirates: 4.0.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants