Skip to content

package.json should use conditional exports, else esm won't work inexplicitly #310

Description

@loynoir

Actual

inexplicitly

import {compare} from 'fast-json-patch'
console.log({compare})
import {compare} from 'fast-json-patch'
        ^^^^^^^
SyntaxError: Named export 'compare' not found. The requested module 'fast-json-patch' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'fast-json-patch';
const {compare} = pkg;

explicitly

import {compare} from 'fast-json-patch/index.mjs'
console.log({compare})
Could not find a declaration file for module 'fast-json-patch/index.mjs'. 
'/path/to/node_modules/fast-json-patch/index.mjs' implicitly has an 'any' type.
If the 'fast-json-patch' package actually exposes this module, 
try adding a new declaration (.d.ts) file containing `declare module 'fast-json-patch/index.mjs'
{ compare: [Function: compare] }

Expected

import {compare} from 'fast-json-patch'
console.log({compare})
{ compare: [Function: compare] }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions