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

Declaration files for ESM and ES2015 builds #73

Open
OliverJAsh opened this issue Feb 26, 2020 · 9 comments
Open

Declaration files for ESM and ES2015 builds #73

OliverJAsh opened this issue Feb 26, 2020 · 9 comments

Comments

@OliverJAsh
Copy link
Contributor

When I try to import from rxjs-etc/esm2015/operators/delayUntil, I get an error: Could not find a declaration file for module 'rxjs-etc/esm2015/operators/delayUntil'.

My workaround:

// modules.d.ts
declare module 'rxjs-etc/esm2015/operators/delayUntil' {
  export { delayUntil } from 'rxjs-etc/operators/delayUntil';
}

Perhaps this library should enable declaration for the ESM and ES2015 builds, so we don't have to do this?

@cartant
Copy link
Owner

cartant commented Feb 26, 2020

Hmm, the intention is for those to be consumed by the bundler, rather than directly.

@OliverJAsh
Copy link
Contributor Author

I guess that makes sense when importing from the root, since the package manifest will redirect the bundler to one of the builds, but in this case I want to import from a sub module. Unless I use something webpack configuration to rewrite my paths.

@cartant
Copy link
Owner

cartant commented Feb 26, 2020

Bundler configurations are the worst. There should be a package.json in the operators directory, though, so maybe - just maybe - using that import location might work?

import { delayUntil } from "rxjs-etc/esm2015/operators";

@OliverJAsh
Copy link
Contributor Author

For that to work I think we would need to add a package.json and declarations inside that folder?

@cartant
Copy link
Owner

cartant commented Feb 26, 2020

I just had a look at the dist and there isn't a package.json in the esm2015/operators directory. Yeah, if you create one it might solve the problem. You should be able to tell it the relative path to the declarations. Have a look at the package.json that's in source/operators for an example:

https://github.com/cartant/rxjs-etc/blob/master/source/operators/package.json

@cartant
Copy link
Owner

cartant commented Feb 26, 2020

I've had the chance to play with it. If the following package.json is added to esm2015/operators it works fine, for me:

{
  "name": "rxjs-etc/operators",
  "main": "./index.js",
  "typings": "../../operators/index.d.ts",
  "sideEffects": false
}

I suppose I can add those to the distributions, but, TBH, I'm also inclined to bump all of my packages by a major version and publish them as ES modules targeting es2019. I'm so over this stuff.

@OliverJAsh
Copy link
Contributor Author

IIUC, that would allow importing rxjs-etc/esm2015/operators, but not from rxjs-etc/esm2015/operators/{subModule}? That's why I wonder if it's better to just emit declarations into all build folders. 🤔

I'm so over this stuff.

Completely agree. We're using these modules on Node as well, so not sure how exactly ESM work there yet.

@cartant
Copy link
Owner

cartant commented Feb 26, 2020

That's why I wonder if it's better to just emit declarations into all build folders. 🤔

Yeah, I'm inclined to agree.

@cartant
Copy link
Owner

cartant commented Feb 27, 2020

FYI, I'm giving serious consideration to exporting es2020 CommonJS via main and es2020 ES modules via exports. Hopefully, that would fix this stuff once and for all.

See https://nodejs.org/api/esm.html#esm_package_exports

This allows defining a different entry point for Node.js versions that support ECMAScript modules and versions that don't, for example

{
  "main": "./main-legacy.cjs",
  "exports": {
    ".": "./main-modern.cjs"
  }
}

Also https://nodejs.org/api/esm.html#esm_conditional_exports

And https://medium.com/@nodejs/announcing-core-node-js-support-for-ecmascript-modules-c5d6dc29b663

And webpack/webpack#9509

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

No branches or pull requests

2 participants