Skip to content

abendi/typeorm-circular-import

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview

Typeorm 0.3.25 introduced a change around SapDriver.ts in commit https://github.com/typeorm/typeorm/commit/ead4f98ee4cbf07843002f14771ef19ef44c5af1, which breaks deep-importing from typeorm/data-source/DataSource.js due to circular dependencies.

Reproduction steps:

  1. Run the script node index.js, which tries to deep-import from typeorm/data-source/DataSource.js and throws:
    TypeError: Class extends value undefined is not a constructor or null
        at Object.<anonymous> (/code/typeorm-import-issue/node_modules/typeorm/connection/Connection.js:12:39)
        at Module._compile (node:internal/modules/cjs/loader:1730:14)
        at Object..js (node:internal/modules/cjs/loader:1895:10)
        at Module.load (node:internal/modules/cjs/loader:1465:32)
        at Function._load (node:internal/modules/cjs/loader:1282:12)
        at TracingChannel.traceSync (node:diagnostics_channel:322:14)
        at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)
        at Module.require (node:internal/modules/cjs/loader:1487:12)
        at require (node:internal/modules/helpers:135:16)
        at Object.<anonymous> (/code/typeorm-import-issue/node_modules/typeorm/index.js:147:20)
    
    Node.js v22.17.1
    
  2. Now comment in the barrel-import line in index.js and rerun the script. No error this time.

Cause

A runtime import to ConnectionIsNotSetError was added in https://github.com/typeorm/typeorm/commit/ead4f98ee4cbf07843002f14771ef19ef44c5af1#diff-a29f961f9e01ed5b7fd0a24a9d96b0fccc6af60204b94e36959ae2646696372bR3, which triggers an import via the top-level barrel file. From GitHub diff it is not obvious how adding another import could have caused it, but when comparing the compiled output between 0.3.24 and 0.3.25 (https://npmdiff.dev/typeorm/0.3.24/0.3.25/package/driver/sap/SapDriver.js), then we see that the line const __1 = require("../.."); was added for the first time, because ConnectionIsNotSetError is not a type-only import and cannot be omitted from the output unlike rest of the imports from ../... Replacing top-level import with require("../../error/ConnectionIsNotSetError") fixes the issue.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published