caztcha / axe-test

axe-core を利用して、ウェブサイトのアクセシビリティ自動テストを一括的に実行するためのスクリプトです。Node.js ライブラリ「Puppeteer」と併せて使います。
MIT License
20 stars 5 forks source link

Error: Cannot find module が出る #1

Closed nishimotz closed 3 years ago

nishimotz commented 3 years ago

GAAD Japan の懇親会でも出た話題ですが、私も環境構築すると下記のようなエラーが出ました。

$ node axe-test.js > result.csv
internal/modules/cjs/loader.js:896
  throw err;
  ^

Error: Cannot find module '@axe-core/puppeteer/node_modules/axe-core/locales/ja.json'
Require stack:
- /home/nishimotz/work/gh/axe-test/axe-test.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:893:15)
    at Function.Module._load (internal/modules/cjs/loader.js:743:27)
    at Module.require (internal/modules/cjs/loader.js:965:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/home/nishimotz/work/gh/axe-test/axe-test.js:5:23)
    at Module._compile (internal/modules/cjs/loader.js:1076:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
    at Module.load (internal/modules/cjs/loader.js:941:32)
    at Function.Module._load (internal/modules/cjs/loader.js:782:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/home/nishimotz/work/gh/axe-test/axe-test.js' ]
}

下記のようにすると期待通りに動作しました。

$ npm install axe-core を追加で実行

axe-test.js の下記を変更

--- a/axe-test.js
+++ b/axe-test.js
@@ -2,7 +2,7 @@ const { AxePuppeteer } = require('@axe-core/puppeteer');
 const puppeteer = require('puppeteer');

 // テスト結果を日本語で出力するように設定する。
-const AXE_LOCALE_JA = require('@axe-core/puppeteer/node_modules/axe-core/locales/ja.json');
+const AXE_LOCALE_JA = require('axe-core/locales/ja.json');
 const config = {
        locale: AXE_LOCALE_JA
 }

以下、こちらの環境です。

Windows 10 (20H2) WSL2 (Ubuntu 18.04.1 LTS)

$ node -v
v14.10.1
$ npm -v
7.13.0
caztcha commented 3 years ago

ご指摘ありがとうございます。調べてみます。

caztcha commented 3 years ago

@nishimotz ご指摘ありがとうございました。 axe-test.js の中で、テスト結果を日本語で出力するためのロケールのパスを修正しました。 https://github.com/caztcha/axe-test/commit/02069e81cb13eaacbef1329d540dbc9aed719351

原因としては、@axe-core/puppeteer をインストールした際の locale フォルダの格納先が一時的に変わっていたようで、最終的には「@axe-core」ディレクトリ以下ではなく「axe-core」以下になっています。この変更に、axe-test.js 側が追いついていなかったため、不具合が発生していたと思われます。

もしよろしければ、今回修正した axe-test.js にて、試していただけますと幸いです。 (こちらでも、Mac と Windows10 で動作を確認済ですが、もし何かお気づきの点ありましたら、教えていただけますと幸いです。)

nishimotz commented 3 years ago

環境を作り直して動作を確認できました。ありがとうございました。