getgauge/gauge-ts

0.3.1 ignores tsconfig-paths

Closed this issue · 4 comments

Describe the bug
tsconfig-paths seems to be ignored and getting following error after update:

Error: Cannot find module '@/config'
Require stack:
- /var/tmp/tests/stepImplementations/pageActions/write.ts
- /var/tmp/node_modules/gauge-ts/dist/utils/Util.js
- /var/tmp/node_modules/gauge-ts/dist/screenshot/Screenshot.js
- /var/tmp/node_modules/gauge-ts/dist/public/Gauge.js
- /var/tmp/node_modules/gauge-ts/dist/index.js
- /var/tmp/node_modules/gauge-ts/dist/RunnerServer.js
- /var/tmp/[eval].ts. Step implementations classes needs to be exported as default without any constructor
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)
at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] (/var/tmp/node_modules/@cspotcode/source-map-support/source-map-support.js:811:30)
at Function.Module._load (node:internal/modules/cjs/loader:986:27)
at Module.require (node:internal/modules/cjs/loader:1233:19)
at require (node:internal/modules/helpers:179:18)
at Object.<anonymous> (/var/tmp/tests/stepImplementations/pageActions/write.ts:3:1)
at Module._compile (node:internal/modules/cjs/loader:1358:14)
at Module.m._compile (/var/tmp/node_modules/ts-node/src/index.ts:1618:23)
at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
at Object.require.extensions.<computed> [as .ts] (/var/tmp/node_modules/ts-node/src/index.ts:1621:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/var/tmp/tests/stepImplementations/pageActions/write.ts',
'/var/tmp/node_modules/gauge-ts/dist/utils/Util.js',
'/var/tmp/node_modules/gauge-ts/dist/screenshot/Screenshot.js',
'/var/tmp/node_modules/gauge-ts/dist/public/Gauge.js',
'/var/tmp/node_modules/gauge-ts/dist/index.js',
'/var/tmp/node_modules/gauge-ts/dist/RunnerServer.js',
'/var/tmp/[eval].ts'
]
}

To Reproduce

Expected behavior
No error

Desktop (please complete the following information):

  • OS: linux
  • Gauge and plugin version
Commit Hash: 684d870

Plugins
-------
html-report (4.3.1)
screenshot (0.2.0)
ts (0.3.1)
xml-report (0.5.1)
  • Node version v20.14.0
  • Npm version 10.7.0

Additional context
tsconfig.json:

{
  "compilerOptions": {
    "target": "es2017",
    "module": "commonjs",
    "outDir": "./dist",
    "strict": true,
    "lib": ["es2017", "dom"],
    "baseUrl": "./",
    "paths": {
      "@/*": ["*"],
    },
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "typeRoots": ["node_modules/@types", "node_modules/taiko/types"],
    "types": ["node", "taiko"]
  },
  "exclude": [
    "node_modules"
  ]
}
$ yarn why tsconfig-paths
yarn why v1.22.22
[1/4] Why do we have the module "tsconfig-paths"...?
[2/4] Initialising dependency graph...
[3/4] Finding dependency...
[4/4] Calculating file sizes...
=> Found "tsconfig-paths@4.2.0"
info Has been hoisted to "tsconfig-paths"
info This module exists because it's specified in "devDependencies".
info Disk size without dependencies: "432KB"
info Disk size with unique dependencies: "872KB"
info Disk size with transitive dependencies: "872KB"
info Number of shared dependencies: 3
Done in 0.17s.

$ yarn why ts-node
yarn why v1.22.22
[1/4] Why do we have the module "ts-node"...?
[2/4] Initialising dependency graph...
[3/4] Finding dependency...
[4/4] Calculating file sizes...
=> Found "ts-node@10.9.2"
info Reasons this module exists
   - "gauge-ts" depends on it
   - Hoisted from "gauge-ts#ts-node"
info Disk size without dependencies: "1.11MB"
info Disk size with unique dependencies: "2.45MB"
info Disk size with transitive dependencies: "2.72MB"
info Number of shared dependencies: 13
Done in 0.18s.

I've fixed my case by adding explicit registration of tsconfig-paths to my tsconfig.json. However, this code does not seem to work:

const opts = [
"ts-node",
...(hasModule("tsconfig-paths") ? ["-r", "tsconfig-paths/register"] : []),
"-e",
script,
];

explicit registration of tsconfig-paths to my tsconfig.json

@hazzik you give an sample config to show what you mean?

@zabil, I have added this configuration to my tsconfig:

  "ts-node": {
    "require": ["tsconfig-paths/register"]
  }

Found here: https://typestrong.org/ts-node/docs/paths/