bitjson/typescript-starter

Option to work with ESM (ES Module) only libraries like node-fetch

chriszrc opened this issue · 0 comments

  • I'm submitting a ...
    [ ] bug report
    [ x ] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

  • Summary
    Currently, if you add a dependency like node-fetch, it breaks the build/run/test because module is set to commonjs. There is a non trivial amount of configuration to actually reconfigure the project for ESM.

    First you have to setup the project to build esm, which is easy enough because node-fetch gives you the steps:

    node-fetch/node-fetch#1279 (comment)

    However ava requires additional reconfiguration. For ava, you need to:

  • bump the ava dependency to ^4.1.0 - https://github.com/avajs/ava/blob/main/docs/recipes/es-modules.md

  • bump the ava typescript dependency to ^3.0.1 and add the "compile": false property- https://github.com/avajs/typescript/blob/v3.0.1/README.md#enabling-typescript-support

  • as mentioned here though (avajs/ava#2593 (comment)), by default ava will still be looking for files with the .js extension, which isn't what you get from tsc. To finally have the tests pass again, you need to enable --experimental-specifier-resolution=node in the ava config:

    "ava": {
     ....
     "nodeArguments": [
      "--experimental-specifier-resolution=node"
      ],
    }