Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler fails when using noResolve for global types #10678

Closed
plwalters opened this issue Sep 2, 2016 · 14 comments
Closed

Compiler fails when using noResolve for global types #10678

plwalters opened this issue Sep 2, 2016 · 14 comments
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@plwalters
Copy link

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.

@mhegazy
Copy link
Contributor

mhegazy commented Sep 2, 2016

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?

@mhegazy mhegazy added the Needs More Info The issue still hasn't been fully clarified label Sep 2, 2016
@plwalters
Copy link
Author

Tsc

@mhegazy
Copy link
Contributor

mhegazy commented Sep 2, 2016

does any of your files have a header of /// <reference no-default-lib="true"/> in them? can you share a sample?

@plwalters
Copy link
Author

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 ;)

@mhegazy
Copy link
Contributor

mhegazy commented Sep 2, 2016

The errors are generated if the default library is not included. if you do tsc --listfiles you do you see any lib.*.d.ts?

@plwalters
Copy link
Author

plwalters commented Sep 2, 2016

$ 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

@basarat
Copy link
Contributor

basarat commented Sep 2, 2016

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 🌹

@mhegazy
Copy link
Contributor

mhegazy commented Sep 3, 2016

ah.. that makes sense :) thank @basarat for the diagnosis.

@mhegazy
Copy link
Contributor

mhegazy commented Sep 3, 2016

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.

@mhegazy mhegazy added Bug A bug in TypeScript Help Wanted You can do this and removed Needs More Info The issue still hasn't been fully clarified labels Sep 3, 2016
@plwalters
Copy link
Author

plwalters commented Sep 3, 2016

Cool I'll give it a shot when I get home Thanks everyone for taking a look

@plwalters
Copy link
Author

Fixed my issue perfectly thanks for pointing this out @basarat

@mhegazy mhegazy added this to the TypeScript 2.1 milestone Sep 21, 2016
@mhegazy mhegazy modified the milestones: TypeScript 2.1, Future Sep 29, 2016
saschanaz added a commit to saschanaz/TypeScript that referenced this issue May 25, 2017
saschanaz added a commit to saschanaz/TypeScript that referenced this issue May 25, 2017
saschanaz added a commit to saschanaz/TypeScript that referenced this issue May 25, 2017
saschanaz added a commit to saschanaz/TypeScript that referenced this issue May 26, 2017
@rkavalap
Copy link

@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.

@zpdDG4gta8XKpMCd
Copy link

wasted 3 hours fighting this problem

9034725985 added a commit to onewyoming/onewyoming that referenced this issue Feb 26, 2019
not sure how to fix this

see microsoft/TypeScript#10678

$ tsc hackerrank.ts --lib ES2016 --lib DOM
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'.

Found 8 errors.
@RyanCavanaugh
Copy link
Member

Seems like this is solved now. Not following reference paths is the intended behavior of noResolve

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

7 participants