ionic-team / starters

Starter templates for Ionic apps, used by the Ionic CLI
MIT License
460 stars 316 forks source link

Test script fails on Windows: SyntaxError: Invalid regular expression. #1727

Open Quraian opened 2 years ago

Quraian commented 2 years ago

Starter Type: React Starter Template: All I think?

Description: When I try to execute the test script on Windows it fails. The strange thing is that it fails if I did yarn test or npm test but if I copied the exact command in the terminal it works fine! yarn test even works on WSL which is Windows subsystem for Linux!

Here's the error:

PS D:\Code\xxxx\mobile> yarn test
yarn run v1.22.19
$ react-scripts test --transformIgnorePatterns 'node_modules/(?!(@ionic/react|@ionic/react-router|@ionic/core|@stencil/core|ionicons)/)'
'ionicons)' is not recognized as an internal or external command,
operable program or batch file.
[ERROR] Unable to find command: /core
[ERROR] Unable to find command: /react-router
node:events:505
      throw er; // Unhandled 'error' event
      ^

Error: EPIPE: broken pipe, write
    at Socket._write (node:internal/net:55:25)
    at writeOrBuffer (node:internal/streams/writable:389:12)
    at _write (node:internal/streams/writable:330:10)
    at Socket.Writable.write (node:internal/streams/writable:334:10)
    at StreamHandler.handle (C:\Users\m4des\AppData\Roaming\npm\node_modules\@ionic\cli\node_modules\@ionic\cli-framework-output\dist\logger.js:52:21)
    at Logger.log (C:\Users\m4des\AppData\Roaming\npm\node_modules\@ionic\cli\node_modules\@ionic\cli-framework-output\dist\logger.js:146:21)
    at Logger.rawmsg (C:\Users\m4des\AppData\Roaming\npm\node_modules\@ionic\cli\lib\utils\logger.js:13:14)
    at HelpCommand.run (C:\Users\m4des\AppData\Roaming\npm\node_modules\@ionic\cli\commands\help.js:53:26)
    at async Promise.all (index 0)
    at async HelpCommand.execute (C:\Users\m4des\AppData\Roaming\npm\node_modules\@ionic\cli\lib\command.js:81:9)
Emitted 'error' event on Socket instance at:
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  errno: -4047,
  syscall: 'write',
  code: 'EPIPE'
}

  ● Test suite failed to run

    SyntaxError: Invalid regular expression: /'node_modules\\(?!(@ionic\\react/: Unterminated group
        at new RegExp (<anonymous>)

      at calcIgnorePatternRegExp (node_modules/@jest/transform/build/ScriptTransformer.js:1076:10)
      at new ScriptTransformer (node_modules/@jest/transform/build/ScriptTransformer.js:231:31)
      at createScriptTransformer (node_modules/@jest/transform/build/ScriptTransformer.js:1112:23)
      at createTranspilingRequire (node_modules/@jest/transform/build/ScriptTransformer.js:924:29)
      at SearchSource._getOrBuildDependencyResolver (node_modules/@jest/core/build/SearchSource.js:227:59)
      at SearchSource.findRelatedTests (node_modules/@jest/core/build/SearchSource.js:288:43)
      at SearchSource.findTestRelatedToChangedFiles (node_modules/@jest/core/build/SearchSource.js:377:17)
      at SearchSource._getTestPaths (node_modules/@jest/core/build/SearchSource.js:386:19)

error Command failed with exit code 255.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

However, after trial and error I found out the issue/fix, it works fine when I replace the single quotes in the command with an escaped double quote like: "test": "react-scripts test --transformIgnorePatterns \"node_modules/(?!(@ionic/react|@ionic/react-router|@ionic/core|@stencil/core|ionicons)/)\"",

My ionic info:

[WARN] Error loading @capacitor/ios package.json: Error: Cannot find module '@capacitor/ios/package'

       Require stack:
       - C:\Users\m4des\AppData\Roaming\npm\node_modules\@ionic\cli\lib\project\index.js
       - C:\Users\m4des\AppData\Roaming\npm\node_modules\@ionic\cli\lib\index.js
       - C:\Users\m4des\AppData\Roaming\npm\node_modules\@ionic\cli\index.js
       - C:\Users\m4des\AppData\Roaming\npm\node_modules\@ionic\cli\bin\ionic
[WARN] Error loading @capacitor/android package.json: Error: Cannot find module '@capacitor/android/package'

       Require stack:
       - C:\Users\m4des\AppData\Roaming\npm\node_modules\@ionic\cli\lib\project\index.js
       - C:\Users\m4des\AppData\Roaming\npm\node_modules\@ionic\cli\lib\index.js
       - C:\Users\m4des\AppData\Roaming\npm\node_modules\@ionic\cli\index.js
       - C:\Users\m4des\AppData\Roaming\npm\node_modules\@ionic\cli\bin\ionic

Ionic:

   Ionic CLI       : 6.20.1 (C:\Users\m4des\AppData\Roaming\npm\node_modules\@ionic\cli)
   Ionic Framework : @ionic/react 6.2.1

Capacitor:

   Capacitor CLI      : 4.0.1
   @capacitor/android : not installed
   @capacitor/core    : 4.0.1
   @capacitor/ios     : not installed

Utility:

   cordova-res : not installed globally
   native-run  : 1.6.0

System:

   NodeJS : v16.15.0 (C:\Program Files\nodejs\node.exe)
   npm    : 8.16.0
   OS     : Windows 10

Other Information:

jobdn commented 1 year ago

Thank you so much for your solution!