node-typescript-template icon indicating copy to clipboard operation
node-typescript-template copied to clipboard

Not working on windows

Open kennedyoliveira opened this issue 4 years ago • 4 comments

Tried to use this on a windows 10 machine but couldn't make it work, got different errors, like tests doesn't work, if I run the test script I get the following error:

"C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" test --scripts-prepend-node-path=auto

> [email protected] test
> mocha

Error: No test files found

Process finished with exit code 1

If I try to run tests via WebStorm

C:\Users\Kennedy\WebstormProjects\xiv-chat-client\test\index.ts:3
import { expect } from 'chai';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1031:15)
    at Module._compile (node:internal/modules/cjs/loader:1065:27)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:94:18)
    at Object.exports.requireOrImport (C:\Users\Kennedy\WebstormProjects\xiv-chat-client\node_modules\mocha\lib\esm-utils.js:56:20)
    at async Object.exports.loadFilesAsync (C:\Users\Kennedy\WebstormProjects\xiv-chat-client\node_modules\mocha\lib\esm-utils.js:88:20)
    at async singleRun (C:\Users\Kennedy\WebstormProjects\xiv-chat-client\node_modules\mocha\lib\cli\run-helpers.js:125:3)
    at async Object.exports.handler (C:\Users\Kennedy\WebstormProjects\xiv-chat-client\node_modules\mocha\lib\cli\run.js:374:5)

Process finished with exit code 1

If I try to build it:

> [email protected] build
> npm run clean && npm run lint && tsc


> [email protected] clean
> (rm -r ./.nyc_output || true) && (rm -r ./coverage || true) && (rm -r ./dist || true)

'rm' is not recognized as an internal or external command,
operable program or batch file.
'true' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code 1
npm ERR! path C:\Users\Kennedy\WebstormProjects\xiv-chat-client
npm ERR! command failed
npm ERR! command C:\Windows\system32\cmd.exe /d /s /c (rm -r ./.nyc_output || true) && (rm -r ./coverage || true) && (rm -r ./dist || true)

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Kennedy\AppData\Local\npm-cache\_logs\2021-09-04T20_49_56_774Z-debug.log

kennedyoliveira avatar Sep 04 '21 20:09 kennedyoliveira

Honestly, I haven't used this project in quite some time. I'll try to take a look soon to see what's wrong.

chriswells0 avatar Sep 19 '21 01:09 chriswells0

You can replace the clean script in package.json with rd /s /q "./dist" | rd /s /q "./nyc_output" | rd /s /q "./coverage" @kennedyoliveira

Yochyo avatar Oct 01 '21 14:10 Yochyo

Thanks for that, @Yochyo. Does it work for you, @kennedyoliveira?

I haven't really used Windows in more than a decade (since XP), so I'm admittedly a little out of touch and rarely take it into consideration. It would be nice to make these commands work cross-platform.

I just did a quick search and found this, but I'd hate to add a bunch of dependencies just to delete generated files:

https://docgov.dev/posts/npm-scripts/#delete-files--folder

I kind of like the last answer on SO, which is to use rm *.js || del *.js as a cross-platform delete:

https://stackoverflow.com/questions/48120889/cross-platform-rm-command#67216575

Does this line work for you?

"clean": "(rm -r ./.nyc_output || del ./.nyc_output || true) && (rm -r ./coverage || del ./coverage || true) && (rm -r ./dist || del ./dist || true)",

or this one?

"clean": "(rm -r ./.nyc_output || rd /s /q ./.nyc_output || true) && (rm -r ./coverage || rd /s /q ./coverage || true) && (rm -r ./dist || rd /s /q ./dist || true)",

chriswells0 avatar Nov 21 '21 21:11 chriswells0

I found a solution for "Error: No test files found" (running Git Bash on Windows 10):

  • Delete file test/mocha.opts
  • Add file .mocharc.js to the root of the project with the following contents:
"use strict"

module.exports = {  
  exit: true,
  bail: true,
  slow: 1000,
  recursive: true,
  extension: ['ts'],
  require: ["ts-node/register", "source-map-support/register"]
}
  • Rerun npm run cover:check

Also, @chriswells0, none of the lines worked, but this one works both on linux and on windows:

"clean": "node -e \"var { rmdirSync, existsSync } = require('fs'), path = require('path'); ['./.nyc_output', './coverage', './dist'].forEach(fPath => {if (existsSync(path.join(__dirname, fPath))) rmdirSync(path.join(__dirname, fPath), { recursive: true })}); process.exit(0);\""

DarkenLM avatar Mar 19 '22 22:03 DarkenLM

The mocha config was migrated at the end of last year. I've added the clean command as provided. Please let me know if anyone still has a problem on Windows and we'll reopen the issue.

chriswells0 avatar Jul 08 '23 16:07 chriswells0