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

estrella doesn't seem to be working within ESM context #51

Open
danielberndt opened this issue Jan 25, 2022 · 6 comments · May be fixed by #53
Open

estrella doesn't seem to be working within ESM context #51

danielberndt opened this issue Jan 25, 2022 · 6 comments · May be fixed by #53

Comments

@danielberndt
Copy link

As more and more dependencies are updating to ESM, I've figured it's time to bite the bullet and make my project ESM-ready as well.

But adding "type": "module" to my project's package.json leads to these two issues when running node build.js:

  1.   import {build, cliopts} from "estrella";
              ^^^^^
      SyntaxError: Named export 'build' not found. The requested module 'estrella' is a CommonJS module, which may not support all module.exports as named exports.
      CommonJS modules can always be imported via the default export, for example using:
      
      import pkg from 'estrella';
      const {build, cliopts} = pkg;
    

    the proposed workaround works though.

  2. TypeError: Cannot read properties of undefined (reading 'filename')
    this is due to this code:

    export const isCLI = module.id == "." || process.mainModule.filename == __filename

    process.mainModule does not seem to exist in ESM.

@ptim
Copy link

ptim commented Feb 3, 2022

I'm experiencing the second issue, too.

The solution to 1. is listed in the error message - if I destructure the estrella import I can repro your issue, but it works fine for me like:

// fails:
// import { build } from "estrella";

// works:
import estrella from 'estrella'
const { build } = estrella

@ptim
Copy link

ptim commented Feb 3, 2022

TypeError: Cannot read properties of undefined (reading 'filename')

I wonder if this is due to "Breaking API change to WatchCallback" in https://github.com/rsms/estrella/releases/tag/v1.4.0?

Downgrading estrella to 1.3.x resolves my issue 👍

Context / repro: I'm playing with https://github.com/sunderjs/sunder-worker-template (see build.js, and I recklessly upgraded all deps 😆

@mhamann
Copy link

mhamann commented Feb 11, 2022

I'm experiencing the second issue (TypeError: Cannot read properties of undefined (reading 'filename')) as well on a project that worked fine with v1.3.x.

I need 1.4.x because I'm building a browser JS bundle and without the sourcesContent option, my sourcemaps are broken.

(@ptim ironically, I was using the same template for my use case)

@mhamann mhamann linked a pull request Feb 11, 2022 that will close this issue
@mhamann
Copy link

mhamann commented Feb 11, 2022

I proposed a fix via #53. it works locally for me and all tests pass.

@johnie
Copy link

johnie commented Jul 7, 2022

This issue is still relevant.

@krznbtni
Copy link

Any chance to accept the PR?

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

Successfully merging a pull request may close this issue.

5 participants