axe-core-npm
axe-core-npm copied to clipboard
Cannot import earl-reporter
Product: reporter-earl
Expectation: After installation with npm install @axe-core/reporter-earl
module should load correctly via const reporter = require('@axe-core/reporter-earl')
Actual: Getting an error on the require statement:
throw err;
^
Error: Cannot find module '/home/repos/purple-hats/node_modules/@axe-core/reporter-earl/dist/axeReporterEarl.js'. Please verify that the package.json has a valid "main
" entry
at tryPackage (internal/modules/cjs/loader.js:321:19)
at Function.Module._findPath (internal/modules/cjs/loader.js:534:18)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:888:27)
at Function.Module._load (internal/modules/cjs/loader.js:746:27)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:93:18)
at Object.<anonymous> (/home/paul/Work/CivicActions/repos/purple-hats/crawlers/commonCrawlerFunc.js:4:18)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:93:18)
at Object.<anonymous> (/home/paul/Work/CivicActions/repos/purple-hats/crawlers/crawlSitemap.js:7:5)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:93:18)
at Object.<anonymous> (/home/paul/Work/CivicActions/repos/purple-hats/combine.js:4:5)
at Module._compile (internal/modules/cjs/loader.js:1085:14) {
code: 'MODULE_NOT_FOUND',
path: '/home/paul/Work/CivicActions/repos/purple-hats/node_modules/@axe-core/reporter-earl/package.json',
requestPath: '@axe-core/reporter-earl'
}
WARNING: An unexpected error has occurred. Please try again later.
Motivation: Trying to get the reporter to load and run in axe via puppeteer:
await Apify.utils.puppeteer.injectFile(page, axeScript);
const results = await page.evaluate(() => {
return axe.run({ resultTypes: ['violations'], reporter });
});
axe-core version: 4.4.1
@axe-core/[integration]: 4.4.2
- Node version: v14.18.2
- Platform: Linux
Hi @starsinmypockets,
When using @axe-core/reporter-earl
with node's require module syntax you will need to do the following since the main export is a default export
const reporter = require('@axe-core/reporter-earl').default;
Please feel free to respond if further assistance is needed.
The import is just failing.
I am able to import the module as follows:
require('@axe-core/reporter-earl/dist/src/axeReporterEarl').default
but the run (in the code sample in the ticket description) doesn't export the report.
Related question from last year https://github.com/dequelabs/axe-core-npm/issues/221
and also this one https://github.com/dequelabs/axe-core-npm/issues/88