Skip to content
This repository was archived by the owner on Jan 26, 2019. It is now read-only.

tsconfig should exclude files from public directory #159

Open
ianschmitz opened this issue Sep 12, 2017 · 4 comments
Open

tsconfig should exclude files from public directory #159

ianschmitz opened this issue Sep 12, 2017 · 4 comments

Comments

@ianschmitz
Copy link
Contributor

ianschmitz commented Sep 12, 2017

Is this a bug report?

Yes

Can you also reproduce the problem with npm 4.x?

Yes

Environment

  1. npm ls react-scripts-ts (if you haven’t ejected): 2.6.0
  2. node -v: 8.4.0
  3. npm -v: 5.3.0

Then, specify:

  1. Operating system: Windows 10

Steps to Reproduce

(Write your steps here:)

  1. Copy node_modules folder to public directory
  2. Run npm start
  3. Notice errors during startup in console. For example i see error:
C:\projects\test\node_modules\@types\node\index.d.ts
(43,11): error TS2451: Cannot redeclare block-scoped variable 'Error'.

Expected Behavior

Only files from src/ should be included in build.

Actual Behavior

Files from public/ are included.

An easy solution was for me to either:

  1. Add public to exclude array in tsconfig.json. or
  2. Replace exclude array with include array with src/**/* as only element.

It seems to me that 2 is preferable if we intend only to be looking at the src directory. There may be drawbacks that I'm not aware of.

@ianschmitz
Copy link
Contributor Author

ianschmitz commented Sep 17, 2017

After considering #152, a potential solution could be something like:

  "include": [
    "src/**/*"
  ],
  "exclude": [
    "src/setupTests.ts",
    "src/**/*.{test,spec}.{ts,tsx}",
    "src/**/__tests__/*"
  ]

@DorianGrey
Copy link
Collaborator

While adding an exclusion or an explicit inclusion should not be a problem, I don't understand why anyone should do this:

Copy node_modules folder to public directory

Can you elaborate the use case for this? It's just that this folder is not intended for source files, neither your own nor those from libraries. If you really have to serve content from the node_modules directory directly - and you should not need to do this in almost every case - I suppose there are better ways to achieve this.

@wmonk
Copy link
Owner

wmonk commented Sep 18, 2017

Yes agree with @DorianGrey, seems like an odd use case. However, I do think we should only be including the src directory in tsconfig, as this fits with how webpack is setup to only allow the importing of files within this dir. Happy to merge a PR for this 😄

@ianschmitz
Copy link
Contributor Author

Sorry I should have elaborated. Im not proposing to try to support node modules in the public directory. It was simply an easy way to reproduce the fact that the it appears files inside public are being consumed by typescript.

peterblazejewicz added a commit to peterblazejewicz/create-react-app-typescript that referenced this issue Sep 20, 2017
The explicit property declaration is based on comment from:
wmonk#159 https://git.io/v5hxz
and TS handbook:
https://git.io/v5hxK

Thanks!
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants