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

Package subpath './lib/command.js' is not defined by "exports" using jasmine-xml-reporter #203

Closed
mitaly opened this issue Jan 20, 2023 · 1 comment

Comments

@mitaly
Copy link

mitaly commented Jan 20, 2023

I am using jasmine-xml-reporter that refers to command.js file of Jasmine package.

Command used for running jasmine test

nyc ./node_modules/jasmine-xml-reporter/bin/jasmine.js --junitreport --output=reports/unit-test --filePrefix=junit-report --config=./jasmine.json

Jasmine.json config file

{ "spec_dir": "./tests", "spec_files": [ "**/*[sS]pec.ts" ], "helpers": ["./tests/helpers/reporter.js"], "stopSpecOnExpectationFailure": false, "random": false }

Error while running tests

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/command.js' is not defined by "exports" in D:\Library\chargeragentcommunication\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._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] (D:\Library\chargeragentcommunication\node_modules\@cspotcode\source-map-support\source-map-support.js:811:30) 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) { code: 'ERR_PACKAGE_PATH_NOT_EXPORTED' }

File contents of jasmine-xml-reporter/bin/jasmine.js

var path = require('path'),
Command = require('jasmine/lib/command.js'),
Jasmine = require('jasmine/lib/jasmine.js');

var jasmine = new Jasmine({ projectBaseDir: path.resolve() });
var examplesDir = path.resolve('jasmine-core', 'example', 'node_example');
var command = new Command(path.resolve(), examplesDir, console.log);

require('jasmine-xml-reporter/boot.js');

command.run(jasmine, process.argv.slice(2));

Versions used:

"jasmine-xml-reporter": "^1.2.1"
"jasmine": "^4.0.0"

@mitaly mitaly changed the title Unable to run jasmine tests using jasmine-xml-reporter Package subpath './lib/command.js' is not defined by "exports" using jasmine-xml-reporter Jan 20, 2023
@sgravrock
Copy link
Member

Command isn't part of the public interface, and it can no longer be accessed as of 4.0. Jasmine is part of the public interface but needs to be accessed through the default export. We added the exports entry, which prevents subpath imports, partly for better compatibility with various tools and partly to reduce the risk of people accidentally depending on private APIs that might change at any time.

Unfortunately, while that change makes it less likely that packages will depend on internal implementation details in the future, it breaks packages like jasmine-xml-reporter that already did so.

(In fairness to the author of jasmine-xml-reporter, that wasn't a particularly unreasonable thing to do back in 2016. We didn't clearly document the public API of the jasmine package back then. And even if we had, the idea that packages should only depend on the documented public interfaces of other packages wasn't well established.)

You can hook up the JUnitXmlReporter from jasmine-reporters yourself in a few different ways:

I hope this helps.

@sgravrock sgravrock closed this as not planned Won't fix, can't repro, duplicate, stale Jan 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants