bitjson/typescript-starter

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

rxluz opened this issue ยท 5 comments

rxluz commented
  • I'm submitting a ...
    [x ] bug report
    [ ] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

  • Summary
    When you select the option to create a pure javascript project without Node neither DOM and you run the initial command described in README (npm run watch) the build fails.

  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)

> 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.

got these errors too.

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

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?

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.

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!

Hey all โ€“ the latest release of typescript-starter should solve this issue, but please let me know if you're still having trouble. ๐Ÿ‘