estrella icon indicating copy to clipboard operation
estrella copied to clipboard

estrella doesn't seem to be working within ESM context

Open danielberndt opened this issue 3 years ago • 6 comments

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:

    https://github.com/rsms/estrella/blob/e5b985bd3292ddaa87022b97062be2f18b15b182/src/util.js#L27

    process.mainModule does not seem to exist in ESM.

danielberndt avatar Jan 25 '22 16:01 danielberndt

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 avatar Feb 03 '22 04:02 ptim

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 😆

ptim avatar Feb 03 '22 04:02 ptim

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 avatar Feb 11 '22 05:02 mhamann

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

mhamann avatar Feb 11 '22 06:02 mhamann

This issue is still relevant.

johnie avatar Jul 07 '22 14:07 johnie

Any chance to accept the PR?

krznbtni avatar Jul 22 '22 14:07 krznbtni