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

Cannot find module non-relatively imported #1062

Open
magwas opened this issue Mar 12, 2023 · 0 comments
Open

Cannot find module non-relatively imported #1062

magwas opened this issue Mar 12, 2023 · 0 comments
Labels
support Questions, discussions, and general support

Comments

@magwas
Copy link

magwas commented Mar 12, 2023

Support plan

  • is this issue currently blocking your project? (no):
  • is this issue affecting a production system? (no):

Context

  • node version: v19.7.0
  • module version: "@hapi/lab": "^25.1.2" (is it the question?)
  • environment (e.g. node, browser, native): developing a node module
  • used with (e.g. hapi application, another framework, standalone, ...): standalone
  • any other relevant information:

package.json:

{
  "name": "cdd-ts",
  "version": "1.0.8",
  "description": "Test-time Contract Development framework for TypeScript",
  "main": "bundle/cdd-ts.js",
  "type": "module",
  "directories": {
    "test": "test"
  },
  "scripts": {
    "qa": "npm run lint &&npm run test&& npm run mutate",
    "prepublishOnly": "npx tsc --project tsconfig.json",
    "mutate": "stryker run",
    "test": "jest",
    "lint": "eslint . --ext .ts"
  },
  "jest": {
    "preset": "ts-jest",
    "testEnvironment": "node",
    "roots": [
      "<rootDir>"
    ],
    "modulePaths": [
      "<rootDir>"
    ],
    "moduleDirectories": [
      "node_modules"
    ]
  },
  "dependencies": {
    "fast-deep-equal": "^3.1.3",
    "fast-glob": "^3.2.12",
    "jest-mock": "^29.4.3",
    "tslib": "^2.3.0"
  },
  "devDependencies": {
    "@types/jest": "^29.4.0",
    "@hapi/lab": "^25.1.2",
    "@stryker-mutator/core": "^6.4.1",
    "@stryker-mutator/jest-runner": "^6.4.1",
    "@typescript-eslint/eslint-plugin": "^5.54.1",
    "eslint": "^8.30.0",
    "eslint-config-prettier": "^8.7.0",
    "eslint-config-standard-with-typescript": "^24.0.0",
    "eslint-plugin-import": "^2.27.5",
    "eslint-plugin-n": "^15.6.1",
    "eslint-plugin-promise": "^6.1.1",
    "jasmine-core": "~4.5.0",
    "lab-transform-typescript": "^3.0.1",
    "rollup": "^3.18.0",
    "rollup-plugin-dts": "^5.2.0",
    "stryker-cli": "^1.0.2",
    "typescript": "~4.8.2",
    "typescript-bundle": "^1.0.18",
    "webpack": "^5.76.1",
    "webpack-cli": "^5.0.1",
    "webpack-node-externals": "^3.0.0"
  }
}

tsconfig.json:

{
  "compileOnSave": true,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "bundle",
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "noImplicitOverride": true,
    "noPropertyAccessFromIndexSignature": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "sourceMap": true,
    "declaration": true,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "ES5",
    "module": "Node16",
    "esModuleInterop": true,
    "useDefineForClassFields": false,
    "lib": [
      "ES2022",
      "dom"
    ],
    "types": [
      "jest"
    ]
  },
  "files": [
    "src/cdd-ts.ts",
  ],
  "include": [
    "**/*.ts",
  ],
  "exclude": [
    "node_modules"
  ],
}}

How can we help?

I tried to run lab on my typeScript project both by npx lab --typescript and npx lab --sourcemaps --transform node_modules/lab-transform-typescript

In both cases I receive the error below.

I do have an import { messageFormat } from "src/util/messageFormat";
in a file imported by test/runAllContracts.test.ts.
I could change it to relative import, but vscode in some cases inserts a nonrelative import even though it is configured to insert relative ones. And anyway,
as I have "baseUrl": "./", in my tsconfig.json, I would have expected nonrelative imports to work for all tools.
How can I get lab to follow nonrelative imports?

You can find the current state of my project at https://github.com/kode-konveyor/cdd-ts/tree/bugreport/lab

Error requiring file: /home/mag/project/KodeKonveyor/cdd-ts/test/runAllContracts.test.ts
Cannot find module 'src/util/messageFormat'
Require stack:
- /home/mag/project/KodeKonveyor/cdd-ts/src/runner/runContractsfromList.ts
- /home/mag/project/KodeKonveyor/cdd-ts/src/runner/runAllContracts.ts
- /home/mag/project/KodeKonveyor/cdd-ts/test/runAllContracts.test.ts
- /home/mag/project/KodeKonveyor/cdd-ts/node_modules/mo-walk/lib/index.js
- /home/mag/project/KodeKonveyor/cdd-ts/node_modules/@hapi/lab/lib/cli.js
- /home/mag/project/KodeKonveyor/cdd-ts/node_modules/@hapi/lab/bin/lab
Error: Cannot find module 'src/util/messageFormat'
Require stack:
- /home/mag/project/KodeKonveyor/cdd-ts/src/runner/runContractsfromList.ts
- /home/mag/project/KodeKonveyor/cdd-ts/src/runner/runAllContracts.ts
- /home/mag/project/KodeKonveyor/cdd-ts/test/runAllContracts.test.ts
- /home/mag/project/KodeKonveyor/cdd-ts/node_modules/mo-walk/lib/index.js
- /home/mag/project/KodeKonveyor/cdd-ts/node_modules/@hapi/lab/lib/cli.js
- /home/mag/project/KodeKonveyor/cdd-ts/node_modules/@hapi/lab/bin/lab
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1090:15)
    at Function.Module._load (node:internal/modules/cjs/loader:934:27)
    at Module.require (node:internal/modules/cjs/loader:1157:19)
    at require (node:internal/modules/helpers:119:18)
    at Object.<anonymous> (/home/mag/project/KodeKonveyor/cdd-ts/src/src/runner/runContractsfromList.ts:1:1)
    at Module._compile (node:internal/modules/cjs/loader:1275:14)
    at Object.require.extensions.<computed> [as .ts] (/home/mag/project/KodeKonveyor/cdd-ts/node_modules/@hapi/lab/lib/modules/transform.js:41:28)
    at Module.load (node:internal/modules/cjs/loader:1133:32)
    at Function.Module._load (node:internal/modules/cjs/loader:972:12)
    at Module.require (node:internal/modules/cjs/loader:1157:19)
    at require (node:internal/modules/helpers:119:18)
    at Object.<anonymous> (/home/mag/project/KodeKonveyor/cdd-ts/src/src/runner/runAllContracts.ts:1:1)
    at Module._compile (node:internal/modules/cjs/loader:1275:14)
    at Object.require.extensions.<computed> [as .ts] (/home/mag/project/KodeKonveyor/cdd-ts/node_modules/@hapi/lab/lib/modules/transform.js:41:28)
    at Module.load (node:internal/modules/cjs/loader:1133:32)
    at Function.Module._load (node:internal/modules/cjs/loader:972:12)
    at Module.require (node:internal/modules/cjs/loader:1157:19)
    at require (node:internal/modules/helpers:119:18)
    at Object.<anonymous> (/home/mag/project/KodeKonveyor/cdd-ts/test/runAllContracts.test.ts:1:1)
    at Module._compile (node:internal/modules/cjs/loader:1275:14)
    at Object.require.extensions.<computed> [as .ts] (/home/mag/project/KodeKonveyor/cdd-ts/node_modules/@hapi/lab/lib/modules/transform.js:41:28)
    at Module.load (node:internal/modules/cjs/loader:1133:32)
    at Function.Module._load (node:internal/modules/cjs/loader:972:12)
    at Module.require (node:internal/modules/cjs/loader:1157:19)
    at require (node:internal/modules/helpers:119:18)
    at Object.internals.tryToResolveCJS (/home/mag/project/KodeKonveyor/cdd-ts/node_modules/mo-walk/lib/index.js:144:17)
    at Object.exports.tryToResolve (/home/mag/project/KodeKonveyor/cdd-ts/node_modules/mo-walk/lib/index.js:106:22)
    at Object.internals.traverse (/home/mag/project/KodeKonveyor/cdd-ts/node_modules/@hapi/lab/lib/cli.js:152:39)
    at Object.exports.run (/home/mag/project/KodeKonveyor/cdd-ts/node_modules/@hapi/lab/lib/cli.js:61:21)
    at main (/home/mag/project/KodeKonveyor/cdd-ts/node_modules/@hapi/lab/bin/lab:56:22)
@magwas magwas added the support Questions, discussions, and general support label Mar 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support Questions, discussions, and general support
Projects
None yet
Development

No branches or pull requests

1 participant