Skip to content

ESM compatibility is still an issue #162

@NoOutlet

Description

@NoOutlet

A PR was merged a couple weeks ago that was meant to address ESM compatibility by adding a package.json file in the ESM dist folder with the content { type: "module" }.
Unfortunately I don't think that has solved the issue with ESM compatibility.

I've been working on a project that has been using the JavaScript Delivery SDK for the last year. I'd like to switch to the TypeScript Delivery SDK as all of the documentation recommends, but when I switch to using it and run the development server I am getting an error like this:

Cannot find module '/project/folder/node_modules/@contentstack/core/dist/esm/src/lib/contentstack-core' imported
  from /project/folder/node_modules/@contentstack/core/dist/esm/src/index.js

I believe the issue here is that ESM strictly requires file extensions to be supplied and although the build process is compiling the TypeScript into JavaScript, it doesn't appear to automatically add the ".js" extension to the compiled imports.
I have cloned this repository (contentstack-js-core) and discovered that simply adding the .ts extensions to the local imports causes all sorts of linting errors and prevents building (npm run build) with errors like

error TS2691: An import path cannot end with a '.ts' extension. Consider importing './api-error' instead.

This is even after adding 'import/extensions': ['always'], to the .eslintrc.js and allowImportingTsExtensions: true (with noEmit: true) to the tsconfig.json.

At this point it seems to be quite a lot of Developer Tool friction to even be able to make ESM compatible imports. I had thought to create a fork of this package (and a fork of @contentstack/delivery that uses this fork) to test whether file extensions in @contenstack/core were all that were necessary to get @contentstack/delivery to work properly for my project but I don't have the time to figure out how to disable all of the linting that is prohibiting file extensions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions