Coder Social home page Coder Social logo

ESM export is commonjs about bbi-js HOT 8 CLOSED

manzt avatar manzt commented on September 27, 2024
ESM export is commonjs

from bbi-js.

Comments (8)

manzt avatar manzt commented on September 27, 2024 1

To be discoverable to Node's resolver (and also most bundlers have now implemented), you'd need to use package entrypoints or add "type": "module" to your package.json. FWIW, I think it is more trouble than it's worth to maintain a dual true ESM & commonjs package. There are enough edge cases that it's a massive headache.

I've moved towards any new project just shipping ESM with basically no polyfills/transpiling. Sometimes just TS within JSDoc, so no build step even - package is the source code. But I know that many projects have different communities/concerns and don't have that ability. There's a good guide on the details of ESM here: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

from bbi-js.

cmdcolin avatar cmdcolin commented on September 27, 2024

nice catch. I think it may take some work to make these true ESM packages...produces some errors when using e.g. module:es2020

yarn run v1.22.18
$ tsc --target es2018 --outDir esm --module es2020
node_modules/@types/babel__core/index.d.ts:12:31 - error TS2792: Cannot find module '@babel/parser'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?

12 import { ParserOptions } from '@babel/parser';
                                 ~~~~~~~~~~~~~~~

node_modules/@types/babel__core/index.d.ts:15:20 - error TS2792: Cannot find module '@babel/types'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?

15 import * as t from '@babel/types';
                      ~~~~~~~~~~~~~~

node_modules/@types/babel__generator/index.d.ts:10:20 - error TS2792: Cannot find module '@babel/types'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?

10 import * as t from '@babel/types';
                      ~~~~~~~~~~~~~~

node_modules/@types/babel__template/index.d.ts:9:31 - error TS2792: Cannot find module '@babel/parser'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?

9 import { ParserOptions } from '@babel/parser';
                                ~~~~~~~~~~~~~~~

node_modules/@types/babel__template/index.d.ts:10:48 - error TS2792: Cannot find module '@babel/types'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?

10 import { Expression, Program, Statement } from '@babel/types';
                                                  ~~~~~~~~~~~~~~

node_modules/@types/babel__traverse/index.d.ts:13:20 - error TS2792: Cannot find module '@babel/types'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?

13 import * as t from '@babel/types';
                      ~~~~~~~~~~~~~~

node_modules/@types/babel__traverse/index.d.ts:63:18 - error TS2411: Property 'blacklist' of type 'any[] | undefined' is not assignable to 'string' index type '(VisitNode<S, any> & VisitNode<S, t.Aliases>) | undefined'.

63 export interface TraverseOptions<S = Node> extends Visitor<S> {
                    ~~~~~~~~~~~~~~~

node_modules/@types/babel__traverse/index.d.ts:63:18 - error TS2411: Property 'denylist' of type 'any[] | undefined' is not assignable to 'string' index type '(VisitNode<S, any> & VisitNode<S, t.Aliases>) | undefined'.

63 export interface TraverseOptions<S = Node> extends Visitor<S> {
                    ~~~~~~~~~~~~~~~

node_modules/@types/babel__traverse/index.d.ts:64:5 - error TS2411: Property 'scope' of type 'Scope | undefined' is not assignable to 'string' index type '(VisitNode<S, any> & VisitNode<S, t.Aliases>) | undefined'.

64     scope?: Scope | undefined;
       ~~~~~

node_modules/@types/babel__traverse/index.d.ts:65:5 - error TS2411: Property 'noScope' of type 'boolean | undefined' is not assignable to 'string' index type '(VisitNode<S, any> & VisitNode<S, t.Aliases>) | undefined'.

65     noScope?: boolean | undefined;
       ~~~~~~~

node_modules/@types/babel__traverse/index.d.ts:248:69 - error TS2536: Type '"type"' cannot be used to index type 'T'.

248     type: T extends null | undefined ? undefined : T extends Node ? T['type'] : string | undefined;
                                                                        ~~~~~~~~~

node_modules/@types/jest/index.d.ts:537:51 - error TS2792: Cannot find module 'jest-diff'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?

537             diff(a: any, b: any, options?: import("jest-diff").DiffOptions): string | null;
                                                      ~~~~~~~~~~~

node_modules/@types/jest/index.d.ts:591:44 - error TS2792: Cannot find module 'pretty-format'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?

591     type SnapshotSerializerPlugin = import('pretty-format').Plugin;
                                               ~~~~~~~~~~~~~~~

src/bbi.ts:2:58 - error TS2792: Cannot find module 'generic-filehandle'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?

2 import { LocalFile, RemoteFile, GenericFilehandle } from 'generic-filehandle'
                                                           ~~~~~~~~~~~~~~~~~~~~

src/bbi.ts:3:38 - error TS2792: Cannot find module 'rxjs'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?

3 import { Observable, Observer } from 'rxjs'
                                       ~~~~~~

src/bbi.ts:4:24 - error TS2792: Cannot find module 'rxjs/operators'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?

4 import { reduce } from 'rxjs/operators'
                         ~~~~~~~~~~~~~~~~

src/bbi.ts:6:22 - error TS2792: Cannot find module 'quick-lru'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?

6 import QuickLRU from 'quick-lru'
                       ~~~~~~~~~~~

src/bbi.ts:376:21 - error TS7006: Parameter 'acc' implicitly has an 'any' type.

376       .pipe(reduce((acc, curr) => acc.concat(curr)))
                        ~~~

src/bbi.ts:376:26 - error TS7006: Parameter 'curr' implicitly has an 'any' type.

376       .pipe(reduce((acc, curr) => acc.concat(curr)))
                             ~~~~

src/bigbed.ts:2:45 - error TS2792: Cannot find module 'rxjs'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?

2 import { Observable, Observer, merge } from 'rxjs'
                                              ~~~~~~

src/bigbed.ts:3:29 - error TS2792: Cannot find module 'rxjs/operators'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?

3 import { map, reduce } from 'rxjs/operators'
                              ~~~~~~~~~~~~~~~~

src/bigbed.ts:5:22 - error TS2792: Cannot find module 'quick-lru'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?

5 import QuickLRU from 'quick-lru'
                       ~~~~~~~~~~~

src/bigbed.ts:225:17 - error TS7006: Parameter 'acc' implicitly has an 'any' type.

225         reduce((acc, curr) => acc.concat(curr)),
                    ~~~

src/bigbed.ts:225:22 - error TS7006: Parameter 'curr' implicitly has an 'any' type.

225         reduce((acc, curr) => acc.concat(curr)),
                         ~~~~

src/bigbed.ts:226:13 - error TS7006: Parameter 'x' implicitly has an 'any' type.

226         map(x => {
                ~

src/blockView.ts:2:26 - error TS2792: Cannot find module 'rxjs'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?

2 import { Observer } from 'rxjs'
                           ~~~~~~

src/blockView.ts:5:35 - error TS2792: Cannot find module 'generic-filehandle'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?

5 import { GenericFilehandle } from 'generic-filehandle'
                                    ~~~~~~~~~~~~~~~~~~~~

src/blockView.ts:7:22 - error TS2792: Cannot find module 'quick-lru'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?

7 import QuickLRU from 'quick-lru'
                       ~~~~~~~~~~~

src/blockView.ts:233:15 - error TS2339: Property 'buffer' does not exist on type '{ bytesRead: number; buffer: Buffer; } | undefined'.

233       const { buffer } = await this.cirTreePromise
                  ~~~~~~


Found 29 errors.

from bbi-js.

cmdcolin avatar cmdcolin commented on September 27, 2024

Actually just added the moduleResolution:'node' for a possible fix here... #48

would you be able to test it out? does your ESM system require the .js extensions on imports and things like that? this build does not have that

from bbi-js.

manzt avatar manzt commented on September 27, 2024

Thanks for having a look!

would you be able to test it out?

should be able to check it out later today or tomorrow

does your ESM system require the .js extensions on imports and things like that? this build does not have that.

It does not, just using via a bundler. Although not technically ESM without the extensions (e.g., cannot run node dist/esm/index.js), the "module" field in the package.json is only recognized by bundlers so this export shouldn't be discoverable from nodes module resolver. (read: maybe ESM not the best naming, but should be totally fine).

from bbi-js.

cmdcolin avatar cmdcolin commented on September 27, 2024

the "module" field in the package.json is only recognized by bundlers so this export shouldn't be discoverable from nodes module resolver

gotcha, that's good to know and was basically my intention behind making the module field available...just have a version that has less polyfills/transpilation. would have to dig deeper for the true ESM thing

from bbi-js.

cmdcolin avatar cmdcolin commented on September 27, 2024

went ahead and merged, felt like a safe move as we're not going for the "true ESM" type module here :)

from bbi-js.

cmdcolin avatar cmdcolin commented on September 27, 2024

let me know if anything else comes up though! thanks for reporting

from bbi-js.

manzt avatar manzt commented on September 27, 2024

went ahead and merged, felt like a safe move as we're not going for the "true ESM" type module here :)

Totally agree. Thanks for the quick response/fix! Cheers.

from bbi-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.