Skip to content

Add "type: module" and fix the exports#16

Open
ipeychev wants to merge 1 commit into
Agent-Pattern-Labs:mainfrom
ipeychev:fix-ESM
Open

Add "type: module" and fix the exports#16
ipeychev wants to merge 1 commit into
Agent-Pattern-Labs:mainfrom
ipeychev:fix-ESM

Conversation

@ipeychev
Copy link
Copy Markdown

Hello,

  1. First of all, thank you for working on this project!
  2. Here is a small PR, which updates the package.json and exports to satisfy the TypeScript compiler in more recent configurations, e.g.:
"module": "NodeNext",
"moduleResolution": "NodeNext",
  1. The changes in package-lock.json are only automatically done by npm audit fix, since there were several vulnerabilities in different dependencies.

Thanks,
Iliyan

@AceGreenman
Copy link
Copy Markdown
Contributor

Not sure if I want to turn this into an esm package. Goal is to keep as commonjs as is. Going to close issue. If want to add configs so esm and cjs can add but I believe already there. This was a side project did a while back not so much time available for this. I am closing issue keep being awesome

@ipeychev
Copy link
Copy Markdown
Author

For the record: this is not an improvement. The module is not usable in recent TypeScript configurations. It just cannot be imported, i.e. it is unusable.

@AceGreenman
Copy link
Copy Markdown
Contributor

For the record: this is not an improvement. The module is not usable in recent TypeScript configurations. It just cannot be imported, i.e. it is unusable.

any chance can pass along more details? It currently compiles to CJS, for instance are you asking that it be made compatible with ESM too? This pull request is adding type: "module" which will make it ESM instead of CJS breaking current CJS builds. Did you take that into consideration?

@ipeychev
Copy link
Copy Markdown
Author

Sure, here is the minumim reproducible code:
test-html-to-adf.zip

Steps:

  1. Extract the zip
  2. Execute nvm use (if you use nvm). Othersise, we use NodeJS v24.1.0
  3. Execute npm i, npm run build.
  4. Execute npm run start

It cannot be started. The error is:

$ npm run start

> test-html-to-adf@1.0.0 start
> node dist/index.js

node:internal/modules/esm/resolve:274
    throw new ERR_MODULE_NOT_FOUND(
          ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/me/test-html-to-adf/node_modules/@razroo/html-to-adf/lib/esm/html-to-adf' imported from /Users/me/test-html-to-adf/node_modules/@razroo/html-to-adf/lib/esm/index.mjs
    at finalizeResolution (node:internal/modules/esm/resolve:274:11)
    at moduleResolve (node:internal/modules/esm/resolve:859:10)
    at defaultResolve (node:internal/modules/esm/resolve:983:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:799:12)
    at #cachedDefaultResolve (node:internal/modules/esm/loader:723:25)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:706:38)
    at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:307:38)
    at #link (node:internal/modules/esm/module_job:170:49) {
  code: 'ERR_MODULE_NOT_FOUND',
  url: 'file:///Users/me/test-html-to-adf/node_modules/@razroo/html-to-adf/lib/esm/html-to-adf'
}

Node.js v24.1.0

About:

This pull request is adding type: "module" which will make it ESM instead of CJS breaking current CJS builds.

I don't mind if we fix it any other way, the only thing it matters is to make it working.

We use many different libraries, both CommonJS and ESM, this was the first library with which we had problems.

Thanks,

@AceGreenman
Copy link
Copy Markdown
Contributor

Nodejs 24 is current/experimental and not Lts, so it doesn't make sense to support 24

@ipeychev
Copy link
Copy Markdown
Author

The problem isn't in NodeJS. The same happens with an older version, e.g. 20.9.0:

npm run start

> test-html-to-adf@1.0.0 start
> node dist/index.js

node:internal/errors:497
    ErrorCaptureStackTrace(err);
    ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/me/test-html-to-adf/node_modules/@razroo/html-to-adf/lib/esm/html-to-adf' imported from /Users/me/test-html-to-adf/node_modules/@razroo/html-to-adf/lib/esm/index.mjs
    at new NodeError (node:internal/errors:406:5)
    at finalizeResolution (node:internal/modules/esm/resolve:233:11)
    at moduleResolve (node:internal/modules/esm/resolve:845:10)
    at defaultResolve (node:internal/modules/esm/resolve:1043:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:383:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:352:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:228:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:85:39)
    at link (node:internal/modules/esm/module_job:84:36) {
  url: 'file:///Users/me/test-html-to-adf/node_modules/@razroo/html-to-adf/lib/esm/html-to-adf',
  code: 'ERR_MODULE_NOT_FOUND'
}

Node.js v20.9.0

@AceGreenman
Copy link
Copy Markdown
Contributor

It's not supposed to be used using npm start

@ipeychev
Copy link
Copy Markdown
Author

Feel fee to run the commands directly and you will see the result is the same:

  1. Install
$ npm i

up to date, audited 60 packages in 480ms

10 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
  1. Build
$ npx tsc -p tsconfig.build.json
  1. Execute
$ node dist/index.js
node:internal/modules/esm/resolve:275
    throw new ERR_MODULE_NOT_FOUND(
          ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/me/test-html-to-adf/node_modules/@razroo/html-to-adf/lib/esm/html-to-adf' imported from /Users/me/test-html-to-adf/node_modules/@razroo/html-to-adf/lib/esm/index.mjs
    at finalizeResolution (node:internal/modules/esm/resolve:275:11)
    at moduleResolve (node:internal/modules/esm/resolve:860:10)
    at defaultResolve (node:internal/modules/esm/resolve:984:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:685:12)
    at #cachedDefaultResolve (node:internal/modules/esm/loader:634:25)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:617:38)
    at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:273:38)
    at ModuleJob._link (node:internal/modules/esm/module_job:135:49) {
  code: 'ERR_MODULE_NOT_FOUND',
  url: 'file:///Users/me/test-html-to-adf/node_modules/@razroo/html-to-adf/lib/esm/html-to-adf'
}

Node.js v22.14.0

@AceGreenman
Copy link
Copy Markdown
Contributor

You are supposed to import the html to adf function

@ipeychev
Copy link
Copy Markdown
Author

If you unzip the provided file and read the source, you will see that the code inside was copyied directly from the documentation of the module:

import { convertHtmlToADF } from '@razroo/html-to-adf';

const htmlString = `<p>test <b>this</b></p>`;
const result = convertHtmlToADF(htmlString);
console.log(result);

adding the suggested changes fixes the issue. They might be not the right ones, but if so, please, feel free to fix it the right way. Properly working module is what community needs.

@AceGreenman
Copy link
Copy Markdown
Contributor

Ok I will look over it over the weekend. Maybe add some documentation on how to use

1 similar comment
@AceGreenman
Copy link
Copy Markdown
Contributor

Ok I will look over it over the weekend. Maybe add some documentation on how to use

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants