Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add ".js" extension to StringUtils import #15

Merged
merged 1 commit into from
Feb 18, 2022
Merged

fix: add ".js" extension to StringUtils import #15

merged 1 commit into from
Feb 18, 2022

Conversation

KevinNovak
Copy link
Contributor

This change adds a ".js" file extension to the "StringUtils" import, which makes this project compatible with ESM projects.

Without this change, if you try building with an ESM project you will get the error:

Error: Cannot find module 'MyProject\node_modules\typeorm\util\StringUtils'
    at createEsmNotFoundErr (node:internal/modules/cjs/loader:954:15)
    at finalizeEsmResolution (node:internal/modules/cjs/loader:947:15)
    at resolveExports (node:internal/modules/cjs/loader:482:14)
    at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:999:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (MyProject\node_modules\typeorm-naming-strategies\snake-naming.strategy.js:5:23)
    at Module._compile (node:internal/modules/cjs/loader:1097:14) {
  code: 'MODULE_NOT_FOUND',
  path: 'MyProject\\node_modules\\typeorm\\package.json'
}

@tonivj5
Copy link
Owner

tonivj5 commented Jan 21, 2022

Thanks for the PR @KevinNovak, could it be a problem for users that don't use ESM?

@KevinNovak
Copy link
Contributor Author

I ran a test against both a CommonJS (non-ESM) project and ESM project. This change works on both types of projects.

@harveyappleton
Copy link

@KevinNovak good work, this solved an issue I'm having! @tonivj5 any chance we can get this merged in?

@earthpyy
Copy link

Looking forward for this PR to be merged 😄

@kevelopment
Copy link

Nice job figuring this out 👍

Any chance to get this merged anytime soon? The latest TypeORM Release (0.2.42) added ESM support which apparently leads to a breaking change when using typeorm-naming-strategies in the same project 😞

@earthpyy
Copy link

FYI while waiting for this PR to be merged, the interim fix is to freeze typeorm package version to 0.2.41

package.json

{
  ...
  "dependencies": {
    ...
    "typeorm": "0.2.41",
    ...
  }
}

@kevelopment
Copy link

Can confirm that the suggested fix from @earthpyy works.
We did / achieved the same for now by running npm install --save --save-exact typeorm@0.2.41

@gulaandrij
Copy link

I just moved code from this repo to my project and add this change - works fine

@tonivj5
Copy link
Owner

tonivj5 commented Feb 18, 2022

I'm going to merge this PR and publish as 3.0 👍🏻

@tonivj5 tonivj5 changed the title Add ".js" extension to StringUtils import fix: add ".js" extension to StringUtils import Feb 18, 2022
@tonivj5 tonivj5 merged commit d57340a into tonivj5:master Feb 18, 2022
@tonivj5
Copy link
Owner

tonivj5 commented Feb 18, 2022

Released as https://github.com/tonivj5/typeorm-naming-strategies/releases/tag/3.0.0 🚀

npm ref: https://www.npmjs.com/package/typeorm-naming-strategies/v/3.0.0

Thanks to @KevinNovak! The compat with ESM is being a bit hard these days... 😅

@coyoteecd
Copy link

@tonivj5 I tried updating to the newly released package and I get a compilation error:

(node:17676) UnhandledPromiseRejectionWarning: Error: Cannot find module '[redacted]\node_modules\typeorm\util\StringUtils.js.js'
    at createEsmNotFoundErr (internal/modules/cjs/loader.js:929:15)
    at finalizeEsmResolution (internal/modules/cjs/loader.js:922:15)
    at resolveExports (internal/modules/cjs/loader.js:450:14)
    at Function.Module._findPath (internal/modules/cjs/loader.js:490:31)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:888:27)
    at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] ([redacted]\node_modules\@cspotcode\source-map-support\source-map-support.js:679:30)
    at Function.Module._load (internal/modules/cjs/loader.js:746:27)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:93:18)
    at Object.<anonymous> ([redacted]\node_modules\typeorm-naming-strategies\snake-naming.strategy.js:5:26)

We target commonjs as shown above, without a bundler (we just run tsc on the *.ts files).

@marius-tb
Copy link

typeorm itself actually released a patch that resolved the problem, you probably don't need the change from this PR

@coyoteecd
Copy link

Yep I have the latest patch included (I use a fork from latest typeorm master). Maybe the patch overlaps with this PR?

@marius-tb
Copy link

Yep I have the latest patch included (I use a fork from latest typeorm master). Maybe the patch overlaps with this PR?

yeah try go back to v2 of this package, you'll likely see your problem fixed already

@diogodomanski
Copy link

@tonivj5 I tried updating to the newly released package and I get a compilation error:

(node:17676) UnhandledPromiseRejectionWarning: Error: Cannot find module '[redacted]\node_modules\typeorm\util\StringUtils.js.js'
    at createEsmNotFoundErr (internal/modules/cjs/loader.js:929:15)
    at finalizeEsmResolution (internal/modules/cjs/loader.js:922:15)
    at resolveExports (internal/modules/cjs/loader.js:450:14)
    at Function.Module._findPath (internal/modules/cjs/loader.js:490:31)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:888:27)
    at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] ([redacted]\node_modules\@cspotcode\source-map-support\source-map-support.js:679:30)
    at Function.Module._load (internal/modules/cjs/loader.js:746:27)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:93:18)
    at Object.<anonymous> ([redacted]\node_modules\typeorm-naming-strategies\snake-naming.strategy.js:5:26)

We target commonjs as shown above, without a bundler (we just run tsc on the *.ts files).

Same problem here with commonjs (NestJS project)

@tonivj5
Copy link
Owner

tonivj5 commented Feb 20, 2022

Error: Cannot find module '[redacted]\node_modules\typeorm\util\StringUtils.js.js'

Notice the double .js

@coyoteecd & @diogodomanski I wonder if node or other part of your setup is appending .js at the end of the import/require 😕

@KevinNovak
Copy link
Contributor Author

typeorm itself actually released a patch that resolved the problem, you probably don't need the change from this PR

If the typeorm patch fixes the root cause, I agree this PR should be reverted.

@tonivj5
Copy link
Owner

tonivj5 commented Feb 20, 2022

typeorm itself actually released a patch that resolved the problem, you probably don't need the change from this PR

If the typeorm patch fixes the root cause, I agree this PR should be reverted.

@KevinNovak could you test if using v2 and latest typeorm version works with your ESM project?

@KevinNovak
Copy link
Contributor Author

KevinNovak commented Feb 20, 2022

@tonivj5 Yes, the patch from typeorm v0.2.43 fixes the issue when using typeorm-naming-strategies v2.0.0.

package.json

{
    "dependencies": {
        "typeorm": "0.2.43",
        "typeorm-naming-strategies": "2.0.0"
    }
}

@tonivj5
Copy link
Owner

tonivj5 commented Feb 23, 2022

I'm going to release a new one without this PR... Thanks for check it @KevinNovak 👍🏻

@tonivj5
Copy link
Owner

tonivj5 commented Mar 12, 2022

https://github.com/tonivj5/typeorm-naming-strategies/releases/tag/4.0.0 is out, reverting this change, so it's the same than 2.0.0 👍🏻

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.

9 participants