kontent-ai / kontent-delivery-node-parser

Rich text element parser for node.js & javascript delivery SDK.
MIT License
0 stars 2 forks source link

Incorrect main/module/exports specified in its package.json #1

Closed drewfoster-luminary closed 1 year ago

drewfoster-luminary commented 1 year ago

Brief bug description

When using this package in an Astro project, Astro throws this error error Failed to resolve entry for package "@kontent-ai/delivery-node-parser". The package may have incorrect main/module/exports specified in its package.json.

It looks like

"module": "./dist/esm5/index.js",
"es2015": "./dist/esm/index.js",

in the package.json should read

"module": "./dist/es6/index.js",
"es2015": "./dist/es6/index.js",

as there is no esm5 or esm folder in the package /dist folder, only 'cjs, es6, es2020, esnext'.

Repro steps

There's quite a few steps to reproduce in our demo repo but I believe if you try and add this package to any Vite project, it should throw the same error (as Astro uses Vite under the hood).

If you need more details @Enngage I'm more than happy to record a quick demo video or jump on a Zoom call / Hangout.

Expected behavior

The module references in package.json point to the correct output folder.

Additional context

In our demo Astro project we resolve rich text info from the Delivery API into an object, so that we can create a custom resolver component for outputting the HTML we need.

import { nodeParser } from "@kontent-ai/delivery-node-parser";
import { createRichTextObjectResolver, Elements, linkedItemsHelper } from "@kontent-ai/delivery-sdk";

export default async function resolveRichText(richTextElement: Elements.RichTextElement) {
    const resolvedObject = createRichTextObjectResolver(nodeParser).resolveRichText({
        element: richTextElement,
        linkedItems: linkedItemsHelper.convertLinkedItemsToArray(richTextElement.linkedItems),
    });

    return resolvedObject;
}

but while our editor doesn't throw an error (it resolves the dist/cjs files), the Vite dev server Astro runs under the hood throws an error

Screen Shot 2023-01-11 at 15 27 14

Going into node_modules/@kontent-ai/delivery-node-parser/package.json and changing module and es2015 to the following resolves the issues

"module": "./dist/es6/index.js",
"es2015": "./dist/es6/index.js",
Enngage commented 1 year ago

I've released the PR with this fix by @benmorana in 3.1.0