node.jsjasminenode-modulesjasmine-ts

How to solve "Error: package subpath.." while using jasmine-ts?


I'm running a nodejs project with jasmine and jasmine-ts

i get these errors when i try to run my tests

Error: Package subpath './lib/command' is not defined by "exports" in D:\Projects - Abzo\Project 2\node_modules\jasmine\package.json at new NodeError (node:internal/errors:372:5) at throwExportsNotFound (node:internal/modules/esm/resolve:472:9) at packageExportsResolve (node:internal/modules/esm/resolve:753:3) at resolveExports (node:internal/modules/cjs/loader:482:36) 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:1005:19) at require (node:internal/modules/cjs/helpers:102:18) at Object. (D:\Projects - Abzo\Project 2\node_modules\jasmine-ts\src\index.ts:143:17)

I tried to downgrade my ts-node version to 8.10.2 like in this stackoverflow question Jasmine-ts throwing an error about package subpath but still unsolved.

My script in package.json is "test":"jasmine-ts"


Solution

  • The problem is in the in the exports property of jasmine package.json:

    Jasmine exports only the jasmine.js file

    "exports": "./lib/jasmine.js"
    

    But in the jasmine-ts code there is a require to command file (around row 164)

    const Command = require("jasmine/lib/command");
    

    Now this file is not part of the exports so it throws the error:

    Error: Package subpath './lib/command' is not defined by "exports"

    To fix this jasmine need to export also the command file used by jasmine-ts. I tested with the following changes in jasmine package.json and solve the problem:

    "exports": {
      ".": "./lib/jasmine.js",
      "./lib/command": "./lib/command.js"
    }
    

    Changing the jasmine package.json is not a great solution but for now this is the only solution on top of my mind.
    I'll try open an issue to jasmine github repository.