yiwen-ai / xid-ts

xid is a globally unique id generator thought for the web. A Typescript port of https://github.com/rs/xid.
MIT License
24 stars 2 forks source link

Error when using in ESM project after upgrading to 1.1.3 #11

Closed mattjohnsonpint closed 2 months ago

mattjohnsonpint commented 2 months ago

In a new empty directory, setup a new TypeScript ESM project:

npm init -y
npm pkg set type=module
npm install typescript --save-dev
npx tsc --init --target ES2022 --module ES2020 --moduleResolution Node

Install the previous version of XID:

npm install xid-ts@1.1.1

Create an index.ts with the following:

import { Xid } from 'xid-ts'
console.log(new Xid().toString())

Compile and run:

npx tsc && node index.js

It works, and the output is the string representation of a new XID, as expected.

Now update to the latest version of XID

npm install xid-ts@1.1.3

Compile and run:

npx tsc && node index.js

The following error occurs:

(node:80703) [DEP0151] DeprecationWarning: Package /Users/matt/Code/testxid/node_modules/xid-ts/ has a "main" field set to "dist/cjs/index", excluding the full filename and extension to the resolved file at "dist/cjs/index.js", imported from /Users/matt/Code/testxid/index.js.
 Automatic extension resolution of the "main" field is deprecated for ES modules.
(Use `node --trace-deprecation ...` to show where the warning was created)
file:///Users/matt/Code/testxid/index.js:1
import { Xid } from 'xid-ts';
         ^^^
SyntaxError: The requested module 'xid-ts' does not provide an export named 'Xid'
    at ModuleJob._instantiate (node:internal/modules/esm/module_job:132:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:214:5)
    at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
    at async loadESM (node:internal/process/esm_loader:28:7)
    at async handleMainPromise (node:internal/modules/run_main:113:12)

Node.js v20.11.1
zensh commented 2 months ago

@mattjohnsonpint Thank you for reporting. It has been fixed at v1.1.4