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

[8.6.2] TypeError: Unable to require file #954

Closed
backbone87 opened this issue Feb 2, 2020 · 5 comments
Closed

[8.6.2] TypeError: Unable to require file #954

backbone87 opened this issue Feb 2, 2020 · 5 comments

Comments

@backbone87
Copy link

After updating from 8.3.0 to 8.6.2 i started getting the following error, when executing typeorm's CLI script via:

docker-compose
	--project-name XXX
	--file ./docker/docker-compose.yaml
	run --rm
	node --require ts-node/register --require tsconfig-paths/register
	--
	./node_modules/typeorm/cli.js --config ./src/db/config.ts
	migration:generate --dir ./src/db/migrations --name new-migration

(node:12-alpine; not specific to the migration:generate command, all CLI operations that load entities fail, setup derived from https://typeorm.io/#/using-cli/if-entities-files-are-in-typescript)

playing around with different versions of ts-node i found that this error started occuring on 8.4.1, but the changes there made no sense for me so i tried out all 8.x versions: (Y = works, N = errors)

8.0.0 Y
8.0.1 Y
8.0.2 N https://github.com/TypeStrong/ts-node/compare/v8.0.1...v8.0.2#diff-f41e9d04a45c83f3b6f6e630f10117feR481
8.0.3 N
8.1.0 N
8.1.1 N
8.2.0 Y https://github.com/TypeStrong/ts-node/compare/v8.1.1...v8.2.0
8.3.0 Y
8.4.0 Y
8.4.1 N https://github.com/TypeStrong/ts-node/compare/v8.4.0...v8.4.1
8.5.0 N
8.5.2 N
8.5.3 N
8.5.4 N
8.6.0 N
8.6.1 N
8.6.2 N

the concrete error message is:

TypeError: Unable to require file: src/db/entities/device.ts
This is usually the result of a faulty configuration or import. Make sure there is a `.js`, `.json` or other executable extension with loader attached before `ts-node` available.
    at getOutput (/app/node_modules/ts-node/src/index.ts:544:17)
    at Object.compile (/app/node_modules/ts-node/src/index.ts:741:32)
    at Module.m._compile (/app/node_modules/ts-node/src/index.ts:820:43)
    at Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Object.require.extensions.<computed> [as .ts] (/app/node_modules/ts-node/src/index.ts:823:12)
    at Module.load (internal/modules/cjs/loader.js:643:32)
    at Function.Module._load (internal/modules/cjs/loader.js:556:12)
    at Module.require (internal/modules/cjs/loader.js:683:19)
    at require (internal/modules/cjs/helpers.js:16:16)
    at Function.PlatformTools.load (/app/src/platform/PlatformTools.ts:137:28)

and for non-working versions before 8.6.0 the error message was:

TypeError: Unable to require `.d.ts` file.
This is usually the result of a faulty configuration or import. Make sure there is a `.js`, `.json` or another executable extension and loader (attached before `ts-node`) available alongside `device.ts`.
    at getOutput (/app/node_modules/ts-node/src/index.ts:368:15)
    at Object.compile (/app/node_modules/ts-node/src/index.ts:393:11)
    at Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Object.require.extensions.<computed> [as .ts] (/app/node_modules/ts-node/src/index.ts:442:12)
    at Module.load (internal/modules/cjs/loader.js:643:32)
    at Function.Module._load (internal/modules/cjs/loader.js:556:12)
    at Module.require (internal/modules/cjs/loader.js:683:19)
    at require (internal/modules/cjs/helpers.js:16:16)
    at Function.PlatformTools.load (/app/src/platform/PlatformTools.ts:137:28)

(/app/src/platform/PlatformTools.ts:137:28 is not a file in my src dir. it is a typeorm file, which probably gets reported in a wrong location due to the source maps included in typeorm. the actual file is at /app/node_modules/typeorm/platform/PlatformTools.js <- js)

running with TS_NODE_DEBUG shows the file being compiled on all non-working versions before crash is device.ts (the first entity file being loaded):

ts-node module._compile /app/src/db/entities/device.ts

(on working versions the exact same compilation works)

i tried to check the changes from 8.0.1 -> 8.0.2 (stopped working), 8.1.1 -> 8.2.0 (started working again) and 8.4.0 -> 8.4.1 (stopped working again), but couldnt really correlate how these changes would affect the problem at hand.

what is even more strange, is that, when just running my app container, everything works fine. the command which is run inside the container:

      ./node_modules/.bin/nodemon
        --watch ./src
        --ext ts
        --legacy-watch
        --exec node
        --inspect=0.0.0.0:9229
        --require ts-node/register
        --require tsconfig-paths/register
        --
        ./src/index.ts

running tsc (or ttsc) on the projects passes without any error or warning.

tsconfig.json

{
  "compilerOptions": {
    "target": "es2019",
    "module": "commonjs",
    "strict": true,
    "importHelpers": true,
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "resolveJsonModule": true,
    "sourceMap": true,
    "baseUrl": ".",
    "outDir": "dist",
    "types": ["node", "keycloak-connect"],
    "typeRoots": ["src/types", "src/features/user/types", "./node_modules/@types"],
    "paths": {
      "@/*": ["src/*"],
      "@@/*": ["*"]
    },
    "lib": ["esnext"],
    "plugins": [{ "transform": "ts-transform-paths" }]
  },
  "include": ["src/**/*.ts"],
  "exclude": ["node_modules"]
}

any ideas?

ref: #797

@cspotcode
Copy link
Collaborator

@backbone87 This looks way too complicated for us to reproduce locally; can you pare down your example to a minimal reproducible example?
https://stackoverflow.com/help/minimal-reproducible-example

For example, you refer to src/index.ts but don't post the code. It's impossible for me to run this locally to debug what's going on.

@rnarayana
Copy link

Same as #876 ?

@cspotcode
Copy link
Collaborator

Closing as it still needs additional info and is likely a duplicate of other, more detailed tickets.

@kafkas
Copy link

kafkas commented Oct 27, 2020

Having the same issue.

@Oxicode
Copy link

Oxicode commented Feb 14, 2023

2023, any news?

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

No branches or pull requests

5 participants