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?
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?
while testing i saw that "root" js files where actually seen
My directory tree
βββ 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?
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.
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.
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.
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.
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
Same issue here. It's *.js files, not *.min.js files. They don't get copied
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?
+1 For reopening
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.
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.
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.
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.
Are you able guys to solve that issue?
Ensure that the Javascript files are in the included path and the allowJs setting is enabled, this's ok
Most helpful comment
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.