TypeScript Version: 2.0.0
Code
I would like for my build process to output all of the javascript files in a separate folder it works fine. When I want to have a shared set of files that various directories can use I can add a baseUrl and a paths property and it works great. The shared files get built to the same output folder and system.js path takes over to resolve on the client side. Because of the path the output wants to output the entire folder structure, so to prevent that I can use the noResolve option, which works great!
The problem is I start getting errors for missing global types.
ex tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"rootDir": "Areas/",
"outDir": "Areas/Shared/dist",
"sourceMap": true,
"target": "es5",
"module": "amd",
"declaration": false,
"noImplicitAny": false,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"lib": ["es2015", "dom"],
"baseUrl": "Areas",
"paths": {
"shared/*": ["Shared/src/*"]
}
},
"filesGlob": [
"./typings/index.d.ts",
"./custom_typings/index.d.ts",
"./Areas/Shared/jspm_packages/**/*.d.ts"
],
"exclude": [
"node_modules",
"Areas/Shared/jspm_packages"
],
"atom": {
"rewriteTsconfig": false
}
}
errors -
error TS2318: Cannot find global type 'Array'.
error TS2318: Cannot find global type 'Boolean'.
error TS2318: Cannot find global type 'Function'.
error TS2318: Cannot find global type 'IArguments'.
error TS2318: Cannot find global type 'Number'.
error TS2318: Cannot find global type 'Object'.
error TS2318: Cannot find global type 'RegExp'.
error TS2318: Cannot find global type 'String'.
Expected behavior:
No errors should be thrown.
Actual behavior:
Errors are thrown, although the process still finishes.
the errors are thrown if the standard library is not included. how are you invoking the compiler? tsc? or through a build tool? if through a build what is it? if not can you share a sample project?
Tsc
does any of your files have a header of /// <reference no-default-lib="true"/> in them? can you share a sample?
None, in fact removing the noResolve option has no issues. I'll try to put together a minimum reproduction but as always of course can't share the original ;)
The errors are generated if the default library is not included. if you do tsc --listfiles you do you see any lib.*.d.ts?
$ tsc --listfiles
outputs
C:/Users/{my-user-name}/AppData/Roaming/npm/node_modules/typescript/lib/lib.dom.d.ts
C:/Users/{my-user-name}/AppData/Roaming/npm/node_modules/typescript/lib/lib.es2015.d.ts
C:/Users/{my-user-name}/AppData/Roaming/npm/node_modules/typescript/lib/lib.es5.d.ts
C:/Users/{my-user-name}/AppData/Roaming/npm/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts
C:/Users/{my-user-name}/AppData/Roaming/npm/node_modules/typescript/lib/lib.es2015.reflect.d.ts
C:/Users/{my-user-name}/AppData/Roaming/npm/node_modules/typescript/lib/lib.es2015.proxy.d.ts
C:/Users/{my-user-name}/AppData/Roaming/npm/node_modules/typescript/lib/lib.es2015.promise.d.ts
C:/Users/{my-user-name}/AppData/Roaming/npm/node_modules/typescript/lib/lib.es2015.iterable.d.ts
C:/Users/{my-user-name}/AppData/Roaming/npm/node_modules/typescript/lib/lib.es2015.symbol.d.ts
C:/Users/{my-user-name}/AppData/Roaming/npm/node_modules/typescript/lib/lib.es2015.generator.d.ts
C:/Users/{my-user-name}/AppData/Roaming/npm/node_modules/typescript/lib/lib.es2015.collection.d.ts
C:/Users/{my-user-name}/AppData/Roaming/npm/node_modules/typescript/lib/lib.es2015.core.d.ts
Compiler fails when using noResolve for global types
Found the reason. It is the combination of using the --lib option with --noResolve. The _bulk_ javascript features are loaded by reference tags and they will not work E.g. the contents of lib.es2015.d.ts are:
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
/// <reference no-default-lib="true"/>
/// <reference path="lib.es2015.core.d.ts" />
/// <reference path="lib.es2015.collection.d.ts" />
/// <reference path="lib.es2015.generator.d.ts" />
/// <reference path="lib.es2015.iterable.d.ts" />
/// <reference path="lib.es2015.promise.d.ts" />
/// <reference path="lib.es2015.proxy.d.ts" />
/// <reference path="lib.es2015.reflect.d.ts" />
/// <reference path="lib.es2015.symbol.d.ts" />
/// <reference path="lib.es2015.symbol.wellknown.d.ts" />
/// <reference path="lib.es5.d.ts" />
PS: @PWKad the listFiles you posted is the one with noResolve switched off. The one with switched on and "lib": ["es2015", "dom"], is more like:
C:/Users/bas/AppData/Roaming/npm/node_modules/typescript/lib/lib.dom.d.ts
C:/Users/bas/AppData/Roaming/npm/node_modules/typescript/lib/lib.es2015.d.ts
Hot fix workaround is to include all the lib files mentioned manually instead of using the bulk ones :rose:
ah.. that makes sense :) thank @basarat for the diagnosis.
So the compiler needs to resolve these regarding of the --noResolve flag. mean while you have to specify all the lib files listed above in your tsconfig.json.
Cool I'll give it a shot when I get home Thanks everyone for taking a look
Fixed my issue perfectly thanks for pointing this out @basarat
@mhegazy @basarat I am using tsc 2.4 RC. Specifying all lib files in tsconfig.json does not work for me when noResolve is true set via gulp-typescript. Anything i am missing.
wasted 3 hours fighting this problem
Most helpful comment
Found the reason. It is the combination of using the
--liboption with--noResolve. The _bulk_ javascript features are loaded byreferencetags and they will not work E.g. the contents oflib.es2015.d.tsare:PS: @PWKad the
listFilesyou posted is the one withnoResolveswitched off. The one with switched on and"lib": ["es2015", "dom"],is more like:Hot fix workaround is to include all the lib files mentioned manually instead of using the
bulkones :rose: