textlint / editor

textlint editor project.
https://textlint-editor.netlify.app/
MIT License
134 stars 9 forks source link

textlint-script-compiler cannot complie when .textlintrc includes textlint-filter-rule-allowlist config #57

Closed HeRoMo closed 3 years ago

HeRoMo commented 3 years ago

My .textlintrc.yml includes textlint-filter-rule-allowlist config, as the following,

filters:
  comments: true
  allowlist:
    allow: 
      - "/^:::details .+$/m"
rules:
  # ~~ some rules config ~~

I complied my .textlintrc.yml, then errors happened, as bellow. (my home dir path replaced by $HOME)

❯ ./node_modules/.bin/textlint-script-compiler --output-dir ./dist-test --metadataName "test" --metadataNamespace "https://example.com" --textlintrc ./.textlintrc.yml
[
  {
    moduleIdentifier: '$HOME/.my-textlint-rules/node_modules/require-from-string/index.js',
    moduleName: './node_modules/require-from-string/index.js',
    loc: '3:13-30',
    message: "Module not found: Error: Can't resolve 'module' in '$HOME/.my-textlint-rules/node_modules/require-from-string'",
    moduleId: 46029,
    moduleTrace: [ [Object], [Object], [Object] ],
    details: "resolve 'module' in '$HOME/.my-textlint-rules/node_modules/require-from-string'\n" +
      '  Parsed request is a module\n' +
      '  using description file: $HOME/.my-textlint-rules/node_modules/require-from-string/package.json (relative path: .)\n' +
      "    Field 'browser' doesn't contain a valid alias configuration\n" +
      '    resolve as module\n' +
      "      $HOME/.my-textlint-rules/node_modules/require-from-string/node_modules doesn't exist or is not a directory\n" +
      "      $HOME/.my-textlint-rules/node_modules/node_modules doesn't exist or is not a directory\n" +
      '      looking for modules in $HOME/.my-textlint-rules/node_modules\n' +
      '        single file module\n' +
      '          using description file: $HOME/.my-textlint-rules/package.json (relative path: ./node_modules/module)\n' +
      '            no extension\n' +
      "              Field 'browser' doesn't contain a valid alias configuration\n" +
      "              $HOME/.my-textlint-rules/node_modules/module doesn't exist\n" +
      '            .js\n' +
      "              Field 'browser' doesn't contain a valid alias configuration\n" +
      "              $HOME/.my-textlint-rules/node_modules/module.js doesn't exist\n" +
      '            .json\n' +
      "              Field 'browser' doesn't contain a valid alias configuration\n" +
      "              $HOME/.my-textlint-rules/node_modules/module.json doesn't exist\n" +
      '            .wasm\n' +
      "              Field 'browser' doesn't contain a valid alias configuration\n" +
      "              $HOME/.my-textlint-rules/node_modules/module.wasm doesn't exist\n" +
      "        $HOME/.my-textlint-rules/node_modules/module doesn't exist\n" +
      "      $HOME/node_modules doesn't exist or is not a directory\n" +
      "      /Users/node_modules doesn't exist or is not a directory\n" +
      "      /node_modules doesn't exist or is not a directory",
    stack: "ModuleNotFoundError: Module not found: Error: Can't resolve 'module' in '$HOME/.my-textlint-rules/node_modules/require-from-string'\n" +
      '    at $HOME/.my-textlint-rules/node_modules/webpack/lib/Compilation.js:1768:28\n' +
      '    at $HOME/.my-textlint-rules/node_modules/webpack/lib/NormalModuleFactory.js:732:13\n' +
      '    at eval (eval at create ($HOME/.my-textlint-rules/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:10:1)\n' +
      '    at $HOME/.my-textlint-rules/node_modules/webpack/lib/NormalModuleFactory.js:274:22\n' +
      '    at eval (eval at create ($HOME/.my-textlint-rules/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:9:1)\n' +
      '    at $HOME/.my-textlint-rules/node_modules/webpack/lib/NormalModuleFactory.js:403:22\n' +
      '    at $HOME/.my-textlint-rules/node_modules/webpack/lib/NormalModuleFactory.js:117:11\n' +
      '    at $HOME/.my-textlint-rules/node_modules/webpack/lib/NormalModuleFactory.js:648:24\n' +
      '    at $HOME/.my-textlint-rules/node_modules/webpack/lib/NormalModuleFactory.js:802:8\n' +
      '    at $HOME/.my-textlint-rules/node_modules/webpack/lib/NormalModuleFactory.js:922:5',
    compilerPath: undefined
  }
]
[
  {
    moduleIdentifier: '$HOME/.my-textlint-rules/node_modules/require-from-string/index.js',
    moduleName: './node_modules/require-from-string/index.js',
    loc: '3:13-30',
    message: "Module not found: Error: Can't resolve 'module' in '$HOME/.my-textlint-rules/node_modules/require-from-string'",
    moduleId: 46029,
    moduleTrace: [ [Object], [Object], [Object] ],
    details: "resolve 'module' in '$HOME/.my-textlint-rules/node_modules/require-from-string'\n" +
      '  Parsed request is a module\n' +
      '  using description file: $HOME/.my-textlint-rules/node_modules/require-from-string/package.json (relative path: .)\n' +
      "    Field 'browser' doesn't contain a valid alias configuration\n" +
      '    resolve as module\n' +
      "      $HOME/.my-textlint-rules/node_modules/require-from-string/node_modules doesn't exist or is not a directory\n" +
      "      $HOME/.my-textlint-rules/node_modules/node_modules doesn't exist or is not a directory\n" +
      '      looking for modules in $HOME/.my-textlint-rules/node_modules\n' +
      '        single file module\n' +
      '          using description file: $HOME/.my-textlint-rules/package.json (relative path: ./node_modules/module)\n' +
      '            no extension\n' +
      "              Field 'browser' doesn't contain a valid alias configuration\n" +
      "              $HOME/.my-textlint-rules/node_modules/module doesn't exist\n" +
      '            .js\n' +
      "              Field 'browser' doesn't contain a valid alias configuration\n" +
      "              $HOME/.my-textlint-rules/node_modules/module.js doesn't exist\n" +
      '            .json\n' +
      "              Field 'browser' doesn't contain a valid alias configuration\n" +
      "              $HOME/.my-textlint-rules/node_modules/module.json doesn't exist\n" +
      '            .wasm\n' +
      "              Field 'browser' doesn't contain a valid alias configuration\n" +
      "              $HOME/.my-textlint-rules/node_modules/module.wasm doesn't exist\n" +
      "        $HOME/.my-textlint-rules/node_modules/module doesn't exist\n" +
      "      $HOME/node_modules doesn't exist or is not a directory\n" +
      "      /Users/node_modules doesn't exist or is not a directory\n" +
      "      /node_modules doesn't exist or is not a directory",
    stack: "ModuleNotFoundError: Module not found: Error: Can't resolve 'module' in '$HOME/.my-textlint-rules/node_modules/require-from-string'\n" +
      '    at $HOME/.my-textlint-rules/node_modules/webpack/lib/Compilation.js:1768:28\n' +
      '    at $HOME/.my-textlint-rules/node_modules/webpack/lib/NormalModuleFactory.js:732:13\n' +
      '    at eval (eval at create ($HOME/.my-textlint-rules/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:10:1)\n' +
      '    at $HOME/.my-textlint-rules/node_modules/webpack/lib/NormalModuleFactory.js:274:22\n' +
      '    at eval (eval at create ($HOME/.my-textlint-rules/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:9:1)\n' +
      '    at $HOME/.my-textlint-rules/node_modules/webpack/lib/NormalModuleFactory.js:403:22\n' +
      '    at $HOME/.my-textlint-rules/node_modules/webpack/lib/NormalModuleFactory.js:117:11\n' +
      '    at $HOME/.my-textlint-rules/node_modules/webpack/lib/NormalModuleFactory.js:648:24\n' +
      '    at $HOME/.my-textlint-rules/node_modules/webpack/lib/NormalModuleFactory.js:802:8\n' +
      '    at $HOME/.my-textlint-rules/node_modules/webpack/lib/NormalModuleFactory.js:922:5',
    compilerPath: undefined
  }
]

When I remove filters.allowlist config from .textlint.yml, textlint-script-compiler can compile successfully.

azu commented 3 years ago

https://github.com/textlint/textlint-filter-rule-allowlist/blob/f336ba1dc0e37fc8bc7f32ad2e789b95e8196c7b/package.json#L52 Probably, this error caused by textlint-filter-rule-allowlist's dependencies. webpack can not support module module that is Node.js specific parts.

Probably, we need to remove rc-config-loader from textlint-filter-rule-allowlist's dependencies. Or, we need to make the import statement on-demand like dynamic import.

azu commented 3 years ago

https://github.com/textlint/editor/blob/4fa8b68b9705ea73656341b16714d4ee3e4f4c63/packages/%40textlint/script-compiler/src/compiler.ts#L113-L117 We may resolve this by adding module: false, which I do not test yet.

azu commented 3 years ago

probably, fixed in textlint/textlint-filter-rule-allowlist#11