Skip to content

Fix ECMAScript modules#179

Open
sullyAL wants to merge 11 commits intofrancescov1:masterfrom
sullyAL:master
Open

Fix ECMAScript modules#179
sullyAL wants to merge 11 commits intofrancescov1:masterfrom
sullyAL:master

Conversation

@sullyAL
Copy link
Copy Markdown

@sullyAL sullyAL commented Jan 5, 2026

…-node` and `tsconfig-paths`. Update global ESLint settings, add `@types/rimraf`, and correct various TypeScript imports.
…els` to use `for...of` instead of `forEach`, ensure proper imports of Mongoose models, and update relevant TypeScript function declarations.
@francescov1
Copy link
Copy Markdown
Owner

Aiming to get this in before eow as long as testing looks good!

@francescov1
Copy link
Copy Markdown
Owner

@sullyAL theres a lot of new stuff here, and local dev / tests arent working out of the box. Can you give a quick explanation of the changes? Specifically all the generated lib changes (seems like these should be git ignored?), the rollup usage and how the new ts loader works. Few issues I ran into.

  1. I see a whole bunch of warnings when building:

(!) [plugin typescript] src/helpers/tests/artifacts/files.ts (93:17): @rollup/plugin-typescript TS2339: Property 'select' does not exist on type '{}'.
/Users/francescovirga/Projects/mtgen-sully/src/helpers/tests/artifacts/files.ts:93:17

93     return this.select('meta.data');
                   ~~~~~~

(!) [plugin typescript] src/helpers/tests/artifacts/user.ts (2:35): @rollup/plugin-typescript TS2865: Import 'UserSchema' conflicts with local value, so must be declared with a type-only import when 'isolatedModules' is enabled.
/Users/francescovirga/Projects/mtgen-sully/src/helpers/tests/artifacts/user.ts:2:35

2 import { UserDocument, UserModel, UserSchema, UserObject } from "./user.gen";
                                    ~~~~~~~~~~

(!) [plugin typescript] src/helpers/tests/artifacts/user2.ts (2:37): @rollup/plugin-typescript TS2865: Import 'User2Schema' conflicts with local value, so must be declared with a type-only import when 'isolatedModules' is enabled.
/Users/francescovirga/Projects/mtgen-sully/src/helpers/tests/artifacts/user2.ts:2:37

2 import { User2Document, User2Model, User2Schema } from './user2.gen';
                                      ~~~~~~~~~~~

(!) Circular dependency
src/helpers/generator.ts -> src/parser/schema.ts -> src/helpers/generator.ts
created lib/index.js in 5s
  1. tests are failing to run

> mongoose-tsgen@9.5.3 test
> npx jest --experimental-vm-modules

● Unrecognized CLI Parameter:

  Unrecognized option "experimental-vm-modules".

  CLI Options Documentation:
  https://jestjs.io/docs/cli

but removing the experimental-vm-modules doesnt resolve it either:


> mongoose-tsgen@9.5.3 test
> npx jest

ReferenceError: module is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/Users/francescovirga/Projects/mtgen-sully/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at file:///Users/francescovirga/Projects/mtgen-sully/jest.config.js:1:1
    at ModuleJob.run (node:internal/modules/esm/module_job:234:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:473:24)
    at async importModule (/Users/francescovirga/Projects/mtgen-sully/node_modules/jest-util/build/index.js:987:28)
    at async readConfigFileAndSetRootDir (/Users/francescovirga/Projects/mtgen-sully/node_modules/jest-config/build/index.js:2270:22)
    at async readInitialOptions (/Users/francescovirga/Projects/mtgen-sully/node_modules/jest-config/build/index.js:1147:13)
    at async readConfig (/Users/francescovirga/Projects/mtgen-sully/node_modules/jest-config/build/index.js:918:7)
    at async readConfigs (/Users/francescovirga/Projects/mtgen-sully/node_modules/jest-config/build/index.js:1168:26)
    at async runCLI (/Users/francescovirga/Projects/mtgen-sully/node_modules/@jest/core/build/index.js:1407:7)
    at async Object.run (/Users/francescovirga/Projects/mtgen-sully/node_modules/jest-cli/build/index.js:656:9)

Please ensure everything works as before and is documented

@sullyAL
Copy link
Copy Markdown
Author

sullyAL commented Mar 6, 2026

Hi @francescov1

Apologise did not tested jest but rather tested it manually and everything worked fine , the tests needed some upgrades mainly adding await due to upgrades done on the packages and renamed jest config file to .cjs

All tests are passing now however I had to make some changes due to my setup (Windows) like normalizing CRLF -> LF due to windows line ending mismatch .

Changed the target to es2018 as well because was failing due to that

image

As per initial changes used rollup for the bundler mainly because I'm more familiar with it , updated mongoose, @oclif, ts-jest, eslint, typescript and using tsx as a runtime now also upgraded the requirement from node 9 to node 14 (believe we can make this at least 18 or 20)

…e test assertions to normalize line endings
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