Skip to content

importHelpers option causes compiler errors #14468

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

Closed
ckotzbauer opened this issue Mar 5, 2017 · 18 comments
Closed

importHelpers option causes compiler errors #14468

ckotzbauer opened this issue Mar 5, 2017 · 18 comments
Labels
Bug A bug in TypeScript

Comments

@ckotzbauer
Copy link

TypeScript Version: 2.2.1

Environment:

  • Windows 10
  • Node 7.6.0
  • NPM 4.1.2
  • TypeScript 2.2.1
  • tslib 1.6.0

The recently added compiler option "importHelpers" causes compiler errors. There are several other closed issues where this problem was described: #12724, #12775, #12. This should be fixed, in TS 2.1.5 or 2.2.x but it still occurs.
It's a simple compiler error in the CLI. In vscode (latest version 1.10.1) the "extends" keyword causes the error.

I created a small skeleton which demonstrates this bug: https://github.com/code-chris/tslib-compile-error. This was tested on a windows machine with the specs above.

Expected behavior:
There's no compilation error when "importHelpers" option is enabled.

Actual behavior:
The compilation result is runnable and correct, but there's a compilation error like this:

src/main.ts(5,19): error TS2354: This syntax requires an imported helper but module 'tslib' cannot be found.
@Delagen
Copy link

Delagen commented Mar 5, 2017

I still see this error when use webpack with awesome-typescript-loader in case tslib resolved via webpack

@mhegazy mhegazy added the Bug A bug in TypeScript label Mar 6, 2017
@mhegazy mhegazy assigned ghost Mar 6, 2017
@mhegazy mhegazy added this to the TypeScript 2.3 milestone Mar 6, 2017
@ghost
Copy link

ghost commented Mar 6, 2017

It can't find that module because your module resolution is set to the default, which doesn't look in node_modules. You can fix this by adding "moduleResolution": "node" to your tsconfig.json. We could probably improve the error message here.

@Delagen
Copy link

Delagen commented Mar 7, 2017

Espessialy for @Andy-MS
There is no this module in node_modules or anywhere which can be resolved via moduleResolution.
Path to tslib module written in paths setting of tsconfig.json and at bundle resolved via webpack. All works but dianostics message still appear

@ghost
Copy link

ghost commented Mar 7, 2017

@Delagen Could you provide a repro for your case? Also try using --traceResolution so see where it looks.

@ckotzbauer
Copy link
Author

ckotzbauer commented Mar 7, 2017

@Andy-MS The moduleResoution fixed the bug in my skeleton from my first post. But yes, the message isn't clear.
@Delagen What do you mean with "no this module"?

@Delagen
Copy link

Delagen commented Mar 7, 2017

@Andy-MS https://github.com/Delagen/typescript-issue14468
npm run test -- success

Found 2 issues which not related to webpack or any other. So it's base behavior of TS.
npm run test.fail
When extend another tsconfig.json and have own paths its simply override base config paths section (may be extend?)
npm run test.fail2
When extend another tsconfig.json paths of base config resolved using root baseUrl and not using baseUrl from base config (relative to its path)

@code-chris I mean tslib module installed outside generic moduleResolution from base module.

@ghost
Copy link

ghost commented Mar 7, 2017

@Delagen I created #14527 for your issue. Assuming it happens for all libraries and not just for tslib.

@Delagen
Copy link

Delagen commented Mar 8, 2017

Work as intended ) - expected answer

@davhdavh
Copy link

davhdavh commented Apr 3, 2017

Status on this? Workaround gives me 500+ compiler errors for other modules it cant find, so that's not really a solution.
Adding tslib.d.ts to where my other .d.ts files are doesn't help either.

@ghost
Copy link

ghost commented Apr 3, 2017

@davhdavh Try using --traceResolution in both scenarios. You'll need to get the module resolution to match up with where you're actually storing your modules. If they're in node_modules you should be able to use "moduleResolution": "node". In some cases you may need to use path mapping. More info here.

@davhdavh
Copy link

davhdavh commented Apr 4, 2017

It is given in the command line, and yet it still cannot find it... Only tslib has this problem. Other modules are not resolved either, according to traceResolution, but it doesn't give an error due to those.
I moved tslib.d.ts into the /App folder and no problem.

C:\Program Files (x86)\Microsoft SDKs\TypeScript\2.1\tsc.exe  --noImplicitAny --module AMD --target ES5 --importHelpers --traceResolution --inlineSourceMap --forceConsistentCasingInFileNames --noEmitOnError --locale en-US --listEmittedFiles "<base>\Scripts\typings\tslib\tslib.d.ts" "<base>\App\main.ts" ...
1>  Unknown output: ======== Resolving module 'tslib' from '<base>/App/Admin/viewmodels/admin.ts'. ========
1>  Unknown output: Module resolution kind is not specified, using 'Classic'.
1>  Unknown output: File '<base>/App/Admin/viewmodels/tslib.ts' does not exist.
1>  Unknown output: File '<base>/App/Admin/viewmodels/tslib.tsx' does not exist.
1>  Unknown output: File '<base>/App/Admin/viewmodels/tslib.d.ts' does not exist.
1>  Unknown output: File '<base>/App/Admin/tslib.ts' does not exist.
1>  Unknown output: File '<base>/App/Admin/tslib.tsx' does not exist.
1>  Unknown output: File '<base>/App/Admin/tslib.d.ts' does not exist.
1>  Unknown output: File '<base>/App/tslib.ts' does not exist.
1>  Unknown output: File '<base>/App/tslib.tsx' does not exist.
1>  Unknown output: File '<base>/App/tslib.d.ts' does not exist.
1>  Unknown output: File '<base>/tslib.ts' does not exist.
1>  Unknown output: File '<base>/tslib.tsx' does not exist.
1>  Unknown output: File '<base>/tslib.d.ts' does not exist.
1>  Unknown output: File '<base>/../tslib.ts' does not exist.
1>  Unknown output: File '<base>/../tslib.tsx' does not exist.
1>  Unknown output: File '<base>/../tslib.d.ts' does not exist.
1>  Unknown output: File 'C:/src/cghg/tslib.ts' does not exist.
1>  Unknown output: File 'C:/src/cghg/tslib.tsx' does not exist.
1>  Unknown output: File 'C:/src/cghg/tslib.d.ts' does not exist.
1>  Unknown output: File 'C:/src/tslib.ts' does not exist.
1>  Unknown output: File 'C:/src/tslib.tsx' does not exist.
1>  Unknown output: File 'C:/src/tslib.d.ts' does not exist.
1>  Unknown output: File 'C:/tslib.ts' does not exist.
1>  Unknown output: File 'C:/tslib.tsx' does not exist.
1>  Unknown output: File 'C:/tslib.d.ts' does not exist.
1>  Unknown output: File '<base>/App/Admin/viewmodels/node_modules/@types/tslib.d.ts' does not exist.
1>  Unknown output: File '<base>/App/Admin/viewmodels/node_modules/@types/tslib/package.json' does not exist.
1>  Unknown output: File '<base>/App/Admin/viewmodels/node_modules/@types/tslib/index.d.ts' does not exist.
1>  Unknown output: File '<base>/App/Admin/node_modules/@types/tslib.d.ts' does not exist.
1>  Unknown output: File '<base>/App/Admin/node_modules/@types/tslib/package.json' does not exist.
1>  Unknown output: File '<base>/App/Admin/node_modules/@types/tslib/index.d.ts' does not exist.
1>  Unknown output: File '<base>/App/node_modules/@types/tslib.d.ts' does not exist.
1>  Unknown output: File '<base>/App/node_modules/@types/tslib/package.json' does not exist.
1>  Unknown output: File '<base>/App/node_modules/@types/tslib/index.d.ts' does not exist.
1>  Unknown output: File '<base>/node_modules/@types/tslib.d.ts' does not exist.
1>  Unknown output: File '<base>/node_modules/@types/tslib/package.json' does not exist.
1>  Unknown output: File '<base>/node_modules/@types/tslib/index.d.ts' does not exist.
1>  Unknown output: File '<base>/../node_modules/@types/tslib.d.ts' does not exist.
1>  Unknown output: File '<base>/../node_modules/@types/tslib/package.json' does not exist.
1>  Unknown output: File '<base>/../node_modules/@types/tslib/index.d.ts' does not exist.
1>  Unknown output: File 'C:/src/cghg/node_modules/@types/tslib.d.ts' does not exist.
1>  Unknown output: File 'C:/src/cghg/node_modules/@types/tslib/package.json' does not exist.
1>  Unknown output: File 'C:/src/cghg/node_modules/@types/tslib/index.d.ts' does not exist.
1>  Unknown output: File 'C:/src/node_modules/@types/tslib.d.ts' does not exist.
1>  Unknown output: File 'C:/src/node_modules/@types/tslib/package.json' does not exist.
1>  Unknown output: File 'C:/src/node_modules/@types/tslib/index.d.ts' does not exist.
1>  Unknown output: File 'C:/node_modules/@types/tslib.d.ts' does not exist.
1>  Unknown output: File 'C:/node_modules/@types/tslib/package.json' does not exist.
1>  Unknown output: File 'C:/node_modules/@types/tslib/index.d.ts' does not exist.
1>  Unknown output: File '<base>/App/Admin/viewmodels/tslib.js' does not exist.
1>  Unknown output: File '<base>/App/Admin/viewmodels/tslib.jsx' does not exist.
1>  Unknown output: File '<base>/App/Admin/tslib.js' does not exist.
1>  Unknown output: File '<base>/App/Admin/tslib.jsx' does not exist.
1>  Unknown output: File '<base>/App/tslib.js' does not exist.
1>  Unknown output: File '<base>/App/tslib.jsx' does not exist.
1>  Unknown output: File '<base>/tslib.js' does not exist.
1>  Unknown output: File '<base>/tslib.jsx' does not exist.
1>  Unknown output: File '<base>/../tslib.js' does not exist.
1>  Unknown output: File '<base>/../tslib.jsx' does not exist.
1>  Unknown output: File 'C:/src/cghg/tslib.js' does not exist.
1>  Unknown output: File 'C:/src/cghg/tslib.jsx' does not exist.
1>  Unknown output: File 'C:/src/tslib.js' does not exist.
1>  Unknown output: File 'C:/src/tslib.jsx' does not exist.
1>  Unknown output: File 'C:/tslib.js' does not exist.
1>  Unknown output: File 'C:/tslib.jsx' does not exist.
1>  Unknown output: ======== Module name 'tslib' was not resolved. ========

@ghost
Copy link

ghost commented Apr 4, 2017

That shows that you're using classic resolution. That is usually bad if you are using NPM, so you might want to try "moduleResolution": "node".

@aluanhaddad
Copy link
Contributor

@Andy-MS @davhdavh see also #11434

@davhdavh
Copy link

davhdavh commented Apr 5, 2017

I didn't say I was using npm, although I do use it for the build setup. But for development, it is Visual Studio and for typings, I use NuGet. (Although there is no nuget package for tslib)

@ghost
Copy link

ghost commented Apr 5, 2017

@davhdavh Wherever your modules are, you may need a typeRoots, baseUrl, or path mapping to help find them. You can use --traceResolution to help debug module-not-found errors.
FYI, nuget-published typings are deprecated.

@hinell
Copy link

hinell commented Apr 18, 2017

Same here.
Resolved by: "moduleResolution": "node"

@reppners
Copy link

As I'm using jspm with its folder structure and moduleResolution: "classic" I had to setup the right path mapping in tsconfig.json

"baseUrl": "./jspm_packages",
"paths": {
      "tslib": [
        "npm/[email protected]/tslib.d.ts"
      ],
}

Maybe this example helps someone else to sort out the issue.

@ghost
Copy link

ghost commented May 15, 2017

To summarize: The problem isn't the --importHelpers option, it's that different people have had module resolution fail for various reasons. There's no real bug here, but we could do more to help people understand why they're getting resolution failures. I've created #15845 to track that.

@ghost ghost closed this as completed May 15, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests

7 participants