TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

allowJs + outDir : js files not copied to outDir

Open farfromrefug opened this issue 10 years ago • 18 comments

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?

farfromrefug avatar May 13 '16 12:05 farfromrefug

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?

mhegazy avatar May 13 '16 17:05 mhegazy

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?

farfromrefug avatar May 14 '16 06:05 farfromrefug

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.

mhegazy avatar May 14 '16 22:05 mhegazy

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.

farfromrefug avatar May 15 '16 08:05 farfromrefug

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.

mhegazy avatar May 16 '16 17:05 mhegazy

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.

danlee2025 avatar Mar 07 '18 09:03 danlee2025

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

keyoti avatar Apr 18 '18 20:04 keyoti

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

cyrus-za avatar May 25 '18 12:05 cyrus-za

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?

flyover avatar Jun 23 '18 17:06 flyover

+1 For reopening

ajhool avatar Apr 09 '19 02:04 ajhool

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.

taxilian avatar May 31 '19 00:05 taxilian

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.

mpvosseller avatar Jan 28 '20 13:01 mpvosseller

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 avatar Jan 31 '20 22:01 davidsk

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.

davidsk avatar Feb 01 '20 12:02 davidsk

Are you able guys to solve that issue?

anbturki avatar Oct 21 '20 11:10 anbturki

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

dlutwuwei avatar Oct 26 '20 03:10 dlutwuwei

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.

ZheyangSong avatar Jan 18 '23 13:01 ZheyangSong

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

samchon avatar Nov 15 '23 04:11 samchon