bitjson / typescript-starter

Quickly create and configure a new library or Node.js project
https://bitjson.github.io/typescript-starter/
MIT License
3.48k stars 245 forks source link

NPM run watch doesn't work to JS projects without Node or DOM #166

Closed rxluz closed 4 years ago

rxluz commented 5 years ago
> run-s clean build:main && run-p "build:main -- -w" "test:unit -- --watch"

> trash build test

> tsc -p tsconfig.json

src/types/example.d.ts:24:33 - error TS2503: Cannot find namespace 'NodeJS'.

24   export interface Hash extends NodeJS.ReadWriteStream {
                                   ~~~~~~

src/types/example.d.ts:27:22 - error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig.

27       data: string | Buffer | DataView,
                        ~~~~~~

src/types/example.d.ts:30:15 - error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig.

30     digest(): Buffer;
                 ~~~~~~

Found 3 errors.
Sharlaan commented 5 years ago

got these errors too.

One have to add "node" in tsconfig.json "types": ["node"],

bitjson commented 5 years ago

Hey @rxluz and @Sharlaan – I'm trying to reproduce this, here's what I'm selecting:

$ npx typescript-starter

_                             _      _          _            _
| |_ _  _ _ __  ___ ___ __ _ _(_)_ __| |_ ___ __| |_ __ _ _ _| |_ ___ _ _
|  _| || | '_ \/ -_|_-</ _| '_| | '_ \  _|___(_-<  _/ _` | '_|  _/ -_) '_|
 \__|\_, | .__/\___/__/\__|_| |_| .__/\__|   /__/\__\__,_|_|  \__\___|_|
     |__/|_|                    |_|

? 📦 Enter the new package name: jjjj
? 🔨 What are you making? Javascript library
? 💬 Enter the package description: lll
? 🚄 Will this project use npm or yarn? npm
? 📚 Which global type definitions do you want to include? None — the library wo
n't use any globals or modules from Node.js or the DOM
? 🚀 More fun stuff: (Press <space> to select, <a> to toggle all, <i> to invert 
selection)Enable tslint-immutable, Include .editorconfig, Include VS Code debugg
ing config, Include CircleCI config

But I'm seeing 2 tests passing when I run npm run watch. What settings are you selecting?

sfentress commented 5 years ago

I see this same error when I run npm run doc.

My settings:

? 📦 Enter the new package name: my-package
? 🔨 What are you making? Javascript library
? 💬 Enter the package description: jjjj
? 🚄 Will this project use npm or yarn? npm
? 📚 Which global type definitions do you want to include? None — the library won't use any globals or modules from Node.js or the DOM
? 🚀 More fun stuff: Enable stricter type-checking, Include .editorconfig, Include VS Code debugging config, Include Travis CI config

npm test and npm run build are clean.

But npm run doc gives me

$ npm run doc

> my-project@1.0.0 doc /Users/me/projects/my-project
> run-s doc:html && open-cli build/docs/index.html

> my-project@1.0.0 doc:html /Users/me/projects/my-project
> typedoc src/ --exclude **/*.spec.ts --target ES6 --mode file --out build/docs

Using TypeScript 3.5.3 from /Users/me/projects/my-project/node_modules/@bitjson/typedoc/node_modules/typescript/lib
Error: /Users/me/projects/my-project/src/types/example.d.ts(23)
 Cannot find namespace 'NodeJS'.
Error: /Users/me/projects/my-project/src/types/example.d.ts(26)
 Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig.
Error: /Users/me/projects/my-project/src/types/example.d.ts(29)
 Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig.
marchica commented 4 years ago

Looks like this error is due to including example code in src\types\example.d.ts that relies on NodeJS so it fails when you run any command that calls build.

Workaround: comment out or delete the code in example.d.ts (or as mentioned above you can add node to your project but that's kinda silly because you just told the generator you didn't want it 😆).

Repro steps:

  1. npx typescript-starter and choose JS library and None for global types
  2. cd my-project
  3. Fix ava issues (#234) with npm i ava@3.8.2 and edit package.json to remove sources from ava section
  4. npm run build

Really awesome app! I'm learning a lot by seeing what this can do. Thanks @bitjson!

bitjson commented 4 years ago

Hey all – the latest release of typescript-starter should solve this issue, but please let me know if you're still having trouble. 👍