-
-
Notifications
You must be signed in to change notification settings - Fork 431
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
Build fails if importing a component from node_modules library #278
Comments
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: Update: |
I find a solution : i passed from [email protected] to [email protected] |
Enguerrand, |
Execute the foowing command line :
It will install typescript v1.8.10 as global package, dev dependencies package and local package. |
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 |
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. |
@johnnyreilly https://github.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. UpdateIf I update the tsconfig.json file to remove the "allowJS" flag, the error seems to go away (branch https://github.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 |
Could you retest with ts-loader v0.9.3? We've just added |
Problem persists with 0.9.3 |
Sample project: Use 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! |
Created a PR with a simpler repro : #365 and note about what needs fixing 🌹 |
Advice to any library authors shipping |
Sounds painful! |
@johnnyreilly the lesson was painful. But the setup isn't:
|
🌷 So does the change you were talking about making to ts-loader still stand? |
I have the lost the will to implement it and would not recommend anyone to write a package that ships Again for those interested reasons, the following bad things happen if you ship
Help wanted 🌹We can provide an additional error message if path contains
|
Thanks for the investigation and write up @basarat. What you've said completely makes sense. I like the idea of the error message you suggest. Would it be straightforward to implement? |
From Lines 34 to 36 in a438869
if (outputText === null || outputText === undefined) {
throw new Error(`Typescript emitted no output for ${filePath}`);
} To : if (outputText === null || outputText === undefined) {
const additionalGuidance = filePath.indexOf('node_modules') !== -1
? "You should not need to recompile .ts files in node_modules and should contact the package author to request them to use --declaration --outDir. More https://github.com/TypeStrong/ts-loader/issues/278"
: "";
throw new Error(`Typescript emitted no output for ${filePath}.${additionalGuidance}`);
} Ofcourse this is untested code and devil will be in the details + adding a test similar to #365 🌹 |
Nice! |
FWIW it might be worth turning your findings into a blog post (if you're so minded). It's always an idea to spread the word when it comes to good practice and it seems like this is still new territory. Have you any idea if the TypeScript team have published any thoughts on this? Can't stop thinking of this: Somewhat overplayed I'm sure 😄 |
Sorry I still didn't get the point in the issue by just reading 😞 The problem is "if library author ship .ts in npm package, ts-loader cannot compile it in node_modules". Is this right? |
Unfortunately shipping js/d.ts files is not a solution for me. I have 2 private repositories:
Both repos are written in Typescript.
The problem is that I can't provide precompiled js/d.ts (mainly because of inlining sass files in ts files which is handled by webpack like:
|
What I have done so I don't need to include "/lib" in the import statements is to make an index.js file that exports the lib as the main entry point: index.ts:
That works fine for me unless I need a specific file, but it's not a terrible inconvenience as is. I haven't used typings for my own projects, but if I run into problems, I'll research that. |
Instead of that you can just change your |
For an NPM package, if we ship js files in |
No. Be sure to add |
I often use this kind of structure to arrange my source code:
This lets me use e.g. Any way to fix this, either via project config or an upstream patch? It's killing me, Smalls! Edit: I should note that this pattern works fine with |
Hi @andybarron, I guess you're being bitten by this: https://github.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. 😄 |
I'll give that a shot and get back to you. If there's a better solution, I've yet to hear it 😛 |
Yeah - I feel your pain |
I'm trying to re-export a specific item from https://github.com/quantumjs/vanilla-typescript |
I get so many issues on this I'm wondering about enabling this behaviour behind an opt-in flag |
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:
Don't worry about fixing the tests; I can help with that. |
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. |
I'm facing this issue as well, but infrequently. Sometimes it works, sometimes not.
When try to build again:
In
Edit: I fixed that by adding the sources of the package to my tsconfig.json:
|
I believe I am running into this after restructuring a project with lerna + yarn workspaces.
and then when I add the specified flag, something like: {
// rest of config...
module: {
rules: [
{
test: /\.[jt]sx?$/,
loader: 'ts-loader',
options: {
allowTsInNodeModules: true,
},
exclude: /node_modules((?!@monorepo).)*$/,
include: /node_modules\/@monorepo\/|src\//,
},
]
}
} 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. |
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 |
@ritmos yes, something similar ended up being the issue for me, not a bug with ts-loader after all |
It looks like #773 fixed this—can this be closed, or are there any further concerns? |
I think you're right - closed. |
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)
.ts-loader version: 0.8.2
webpack version: 1.13.1
tsc version: 1.8.10
The text was updated successfully, but these errors were encountered: