Giter Site home page Giter Site logo

Real ESM support about fp-ts-std HOT 9 OPEN

samhh avatar samhh commented on July 20, 2024
Real ESM support

from fp-ts-std.

Comments (9)

samhh avatar samhh commented on July 20, 2024

Should be resolved in the esm branch, however that's blocked by docs-ts: gcanti/docs-ts#59 (comment)

from fp-ts-std.

samhh avatar samhh commented on July 20, 2024

Actually in different projects I'm seeing different results. One works, the other complains about the fp-ts imports. 😒

from fp-ts-std.

samhh avatar samhh commented on July 20, 2024

I think 0.18.0-beta.3 is the first to work fully with both proper ESM and CJS.

Depending on the consuming project different packaging issues can surface, most of which don't reveal themselves when building here.

The latest surprise is that tsc requires the consuming project to be ESM to read a package's exports field, hence the return of the typesVersions hack.

from fp-ts-std.

samhh avatar samhh commented on July 20, 2024

Nope, spoke too soon, the fp-ts imports need updating. 😡

from fp-ts-std.

samhh avatar samhh commented on July 20, 2024

Webpack:

ERROR in ./node_modules/fp-ts-std/dist/esm/URL.js 2:0-34
Module not found: Error: Can't resolve 'fp-ts/Either' in '/path/to/repo/node_modules/fp-ts-std/dist/esm'
Did you mean 'Either.js'?
BREAKING CHANGE: The request 'fp-ts/Either' failed to resolve only because it was resolved as fully specified
(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.

Similar in a Node REPL:

> await import('fp-ts-std/Array')
Uncaught:
Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '/path/to/repo/node_modules/fp-ts/function' is not supported resolving ES modules imported from /path/to/repo/node_modules/fp-ts-std/dist/esm/Array.js
Did you mean to import fp-ts/lib/function.js?
    at new NodeError (node:internal/errors:399:5)
    at finalizeResolution (node:internal/modules/esm/resolve:319:17)
    at moduleResolve (node:internal/modules/esm/resolve:945:10)
    at defaultResolve (node:internal/modules/esm/resolve:1153:11)
    at nextResolve (node:internal/modules/esm/loader:163:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:838:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:77:40)
    at link (node:internal/modules/esm/module_job:76:36) {
  code: 'ERR_UNSUPPORTED_DIR_IMPORT',
  url: 'file:///path/to/repo/node_modules/fp-ts/function'
}

From debugging in the REPL it looks like the imports need to be from lib, not es6.

from fp-ts-std.

samhh avatar samhh commented on July 20, 2024

^ Fixed in 0.18.0-beta.4, however there's been some significant bundle bloat in a CJS project.

from fp-ts-std.

samhh avatar samhh commented on July 20, 2024

I'm interpreting this to mean that fp-ts-std effectively can't be ESM until fp-ts et al are.

Perhaps the bundle bloat could be resolved with some clever bundler.

from fp-ts-std.

samhh avatar samhh commented on July 20, 2024

The bundle bloat mostly goes away if the bundler is configured to rewrite fp-ts/lib imports to fp-ts/es6 (e.g. Webpack's resolve.alias). It doesn't entirely solve it however, and expecting non-ESM bundle-sensitive consumers to do this is a big ask.

from fp-ts-std.

samhh avatar samhh commented on July 20, 2024

The status quo makes the package effectively entirely broken for ESM projects as the subpath exports prevent you from manually importing from /cjs. Curiously if you import a CJS module which in turn imports fp-ts-std it resolves correctly.

from fp-ts-std.

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.