microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.26k stars 12.38k forks source link

allowJs + outDir : js files not copied to outDir #8591

Closed farfromrefug closed 8 years ago

farfromrefug commented 8 years ago

typescript 1.8.10

I am trying to add a js file to my project. My tsconfig.json:

{
    "compilerOptions": {
        "target": "es5",
        "module": "commonjs",
        "removeComments": true,
        "preserveConstEnums": true,
        "moduleResolution": "node",
        "experimentalDecorators": true,
        "noImplicitAny": false,
        "allowJs": true,
        "outDir": "build",
        "noEmitOnError": false
    },

    "exclude": [
        "node_modules",
        "typings/browser.d.ts",
        "typings/browser",
        "build"
    ]
}

When i run tsc the js file is not copied to the outDir. Which you obviously expect as otherwise "requiring" would not work.

Is that an expected behavior?

mhegazy commented 8 years ago

I can not get this to reproduce on a simple example. can you share more context?

also if you run tsc --listFiles do you see your js file in the input list?

farfromrefug commented 8 years ago

while testing i saw that "root" js files where actually seen

My directory tree

src
├── Enums.ts
├── Interfaces.ts
├── Overrides.d.ts
├── es6-init.js
├── main
│   ├── Main.ts
│   ├── bthandler.ts
│   └── serialhandler.ts
├── neosmia
│   ├── lzutf8.min.js
│   └── neosmia.ts
├── noble.d.ts
├── renderer
│   ├── app.tsx
│   ├── components
│   │   ├── BaseComponent.ts
│   │   ├── BottomToolbar.tsx
│   │   ├── DeviceList.tsx
│   │   ├── DeviceView.tsx
│   │   └── SmartComponent.ts
│   ├── deviceControl
│   │   ├── LeftMenu.tsx
│   │   ├── WifiView.tsx
│   │   ├── index.html
│   │   └── test.tsx
│   ├── index.html
│   └── stores
│       └── BaseStore.ts
└── utils.ts

The result of tsc --listFiles

src/main/bthandler.ts(160,14): error TS2420: Class 'TestPeripheral' incorrectly implements interface 'Peripheral'.
  Property 'address' is missing in type 'TestPeripheral'.
src/main/bthandler.ts(184,54): error TS2339: Property 'uuid' does not exist on type 'EventEmitter'.
src/renderer/Stores/BaseStore.ts(1,37): error TS2503: Cannot find namespace 'AltJS'.
src/renderer/deviceControl/test.tsx(24,31): error TS2307: Cannot find module '../components/LocalizedProvider'.
src/renderer/deviceControl/test.tsx(228,23): error TS2322: Type 'typeof MainComponent' is not assignable to type 'string | ComponentClass<any> | StatelessComponent<any>'.
  Type 'typeof MainComponent' is not assignable to type 'StatelessComponent<any>'.
src/renderer/deviceControl/test.tsx(228,23): error TS2322: Type 'typeof MainComponent' is not assignable to type 'string | ComponentClass<any> | StatelessComponent<any>'.
  Type 'typeof MainComponent' is not assignable to type 'StatelessComponent<any>'.
    Type 'typeof MainComponent' provides no match for the signature '(props?: any, context?: any): ReactElement<any>'
src/renderer/app.tsx(110,23): error TS2322: Type 'typeof App' is not assignable to type 'string | ComponentClass<any> | StatelessComponent<any>'.
  Type 'typeof App' is not assignable to type 'StatelessComponent<any>'.
src/renderer/app.tsx(110,23): error TS2322: Type 'typeof App' is not assignable to type 'string | ComponentClass<any> | StatelessComponent<any>'.
  Type 'typeof App' is not assignable to type 'StatelessComponent<any>'.
    Type 'typeof App' provides no match for the signature '(props?: any, context?: any): ReactElement<any>'
src/renderer/deviceControl/LeftMenu.tsx(84,18): error TS2304: Cannot find name 'FormattedMessage'.
typings/main.d.ts(4,1): error TS6053: File 'typings/main/ambient/lodash/index.d.ts' not found.
typings/main.d.ts(5,1): error TS6053: File 'typings/main/ambient/material-ui/index.d.ts' not found.
typings/main.d.ts(12,1): error TS6053: File 'typings/main/definitions/flux/index.d.ts' not found.
typings/main/ambient/react-router/index.d.ts(15,16): error TS2503: Cannot find namespace 'HistoryModule'.
typings/main/ambient/react-router/index.d.ts(241,42): error TS2503: Cannot find namespace 'HistoryModule'.
typings/main/ambient/react-router/index.d.ts(241,75): error TS2503: Cannot find namespace 'HistoryModule'.
typings/main/ambient/react-router/index.d.ts(411,20): error TS2503: Cannot find namespace 'HistoryModule'.
typings/main/ambient/react-router/index.d.ts(411,51): error TS2503: Cannot find namespace 'HistoryModule'.
typings/main/ambient/react-router/index.d.ts(411,75): error TS2503: Cannot find namespace 'HistoryModule'.
typings/main/ambient/react-router/index.d.ts(414,64): error TS2503: Cannot find namespace 'HistoryModule'.
/usr/local/lib/node_modules/typescript/lib/lib.es6.d.ts
src/Enums.ts
src/Interfaces.ts
/Volumes/data/dev/aryballe/neosmia-desktop-app/src/neosmia/neosmia.ts
src/utils.ts
/Volumes/data/dev/aryballe/neosmia-desktop-app/src/main/bthandler.ts
/Volumes/data/dev/aryballe/neosmia-desktop-app/src/main/serialhandler.ts
src/main/Main.ts
src/renderer/components/BaseComponent.ts
/Volumes/data/dev/aryballe/neosmia-desktop-app/src/renderer/Stores/BaseStore.ts
src/renderer/components/SmartComponent.ts
/Volumes/data/dev/aryballe/neosmia-desktop-app/src/renderer/components/BottomToolbar.tsx
/Volumes/data/dev/aryballe/neosmia-desktop-app/src/renderer/components/DeviceList.tsx
/Volumes/data/dev/aryballe/neosmia-desktop-app/src/renderer/components/DeviceView.tsx
src/renderer/app.tsx
/Volumes/data/dev/aryballe/neosmia-desktop-app/src/renderer/deviceControl/WifiView.tsx
/Volumes/data/dev/aryballe/neosmia-desktop-app/src/renderer/deviceControl/test.tsx
src/renderer/deviceControl/LeftMenu.tsx
externalTypings/material-ui.d.ts
src/Overrides.d.ts
src/noble.d.ts
typings/main/ambient/chai/index.d.ts
typings/main/ambient/github-electron/index.d.ts
typings/main/ambient/i18n-node/index.d.ts
typings/main/ambient/mocha/index.d.ts
typings/main/ambient/node/index.d.ts
typings/main/ambient/react-dom/index.d.ts
typings/main/ambient/react-intl/index.d.ts
typings/main/ambient/react-router/index.d.ts
typings/main/ambient/react/index.d.ts
typings/main/definitions/lodash/index.d.ts
typings/main.d.ts
gulpfile.babel.js
src/es6-init.js

As you can see src/neosmia/lzutf8.min.js is ignored. May be you ignore min files?

mhegazy commented 8 years ago

yes. .min files are not picked up automatically. note that the compiler does not copy files, it transpiles them. i doubt that you want to transpile a minfied library file (or any external dependency for that matter). so i would suggest coping the file in a post build step to the output locaiton instead of expecting the compiler to do it for you.

farfromrefug commented 8 years ago

I expect tsc to compile my project. And it's supposed to handle all ts and js files. I understand that it should not transpile a min file but then to respect the fact that it handles the whole project it should copy the min file around. It's so difficult to understand why your file is not copied. There's not even a warning.

mhegazy commented 8 years ago

node_modules, the value of outDir, hidden files, files or folders starting with . (e.g..git), and JavaScript files with .min.js extension are ignored by default when enumerating the files in a folder.

you can list the files you want to include in the "files" list in your tsconfig.json. or pass them on the command-line.

again this will cause your minified file to be transpiled. and i highly recommend not to do that.

danleechina commented 6 years ago

I can understand what @farfromrefug were saying. Because I got this problem too. Currently my solution is to copy the js file to outDir manually.

keyoti commented 6 years ago

I have a X.d.ts and a X.js and nothing (besides other .ts files) is copied/transpiled, is that correct? Doesn't make sense to me

cyrus-za commented 6 years ago

Same issue here. It's .js files, not .min.js files. They don't get copied

flyover commented 6 years ago

I have a similar case where I have a .d.ts created by hand for a .js generated by emscripten.

https://github.com/flyover/imgui-js

The bind-imgui.js file is imported into the imgui.ts file via import * as Bind from "./bind-imgui";. When the module is built by another app, the transpiled imgui.js file is placed in the outDir, but not the bind-imgui.js file.

@mhegazy, would you consider reopening this? Maybe there's a solution where a .js file could be only copied (not transpiled) to the outDir/outFile if it is in "files" and there is a corresponding .d.ts?

ajhool commented 5 years ago

+1 For reopening

taxilian commented 5 years ago

When you use allowJs with a target which is going to a combined output it will include the JS file; why would it not copy when transpiling? Without this we have to find a second build tool to solve the problem. Searching around it's clear there is a ton of confusion on this point.

mpvosseller commented 4 years ago

There appears to be some confusion / mis-information in this thread. The original issue is that *.min.js files are not copied/transpiled to outDir. Sounds like this is the expected behavior (and why the issue was closed).

However other (non-minfied) *.js files ARE copied/transpiled to outDir. You just need to ensure that the Javascript files are in the included path and the allowJs setting is enabled.

Example tsconfig.json:

{
  "compilerOptions": {
    "outDir": "build",
    "allowJs": true,
  },
  "include": ["src/**/*"]
}

With the above setting src/Example.js would get copied/transpiled to build/Example.js

Hope this helps.

davidsk commented 4 years ago

I'm seeing this behaviour. tsc --listfiles does list all the source js files but only the output js files make it into the outDir if compilerOptions: noEmitOnError is set to true.

davidsk commented 4 years ago

tsc --listfiles also seems to force the copy of the js source files to outDir although I haven't been able to reproduce this behaviour in isolation.

anbturki commented 3 years ago

Are you able guys to solve that issue?

dlutwuwei commented 3 years ago

Ensure that the Javascript files are in the included path and the allowJs setting is enabled, this's ok

ZheyangSong commented 1 year ago

I have a similar case where I have a .d.ts created by hand for a .js generated by emscripten.

https://github.com/flyover/imgui-js

The bind-imgui.js file is imported into the imgui.ts file via import * as Bind from "./bind-imgui";. When the module is built by another app, the transpiled imgui.js file is placed in the outDir, but not the bind-imgui.js file.

@mhegazy, would you consider reopening this? Maybe there's a solution where a .js file could be only copied (not transpiled) to the outDir/outFile if it is in "files" and there is a corresponding .d.ts?

LOL, ran into exactly the same issue with the same toolchain.

samchon commented 10 months ago

Hope this feature for prisma case.

https://www.prisma.io/docs/concepts/components/prisma-client/working-with-prismaclient/generating-prisma-client#the-location-of-prisma-client