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

Error when using npm linked dependency #134

Closed
frederikschubert opened this issue Jan 7, 2016 · 4 comments · Fixed by #141
Closed

Error when using npm linked dependency #134

frederikschubert opened this issue Jan 7, 2016 · 4 comments · Fixed by #141
Labels

Comments

@frederikschubert
Copy link

When trying to import a module from a dependency that is linked by npm, the typescript compiler fails to load that file. I don't know if this is a typescript issue or a ts-loader issue.

My setup:
The project named project below in the stacktrace depends on my-dependency. Now when I install my-dependency via npm install my-dependency everything works fine.
But because I want to work on both projects at the same time I link my-dependency via npm link ../my-dependency. This creates the correct symlinks but when I try to bundle my project with webpack the following error is thrown.
This error does not appear if I copy the whole my-dependency directory to my project's node_modules directory.

ts-loader version: 0.7.2
typescript version: 1.7.5
webpack version: 1.12.9

Note: I already used the fix that is suggested in the webpack documentation. It resolved the issues with requiring the loader itself but the issue below remains. Even though the file that the Compiler can't find exists.

Stacktrace:

/Users/user/project/node_modules/typescript/lib/typescript.js:44463
                throw new Error("Could not find file: '" + fileName + "'.");
                ^

Error: Could not find file: '/Users/user/project/node_modules/my-dependency/src/menu-item/index.ts'.
    at getValidSourceFile (/Users/user/project/node_modules/typescript/lib/typescript.js:44463:23)
    at Object.getSyntacticDiagnostics (/Users/user/project/node_modules/typescript/lib/typescript.js:44633:52)
    at /Users/user/project/node_modules/ts-loader/index.js:317:42
    at Array.forEach (native)
    at Compiler.<anonymous> (/Users/user/project/node_modules/ts-loader/index.js:316:14)
    at Compiler.next (/Users/user/project/node_modules/tapable/lib/Tapable.js:69:14)
    at Compiler.<anonymous> (/Users/user/project/node_modules/webpack/lib/CachePlugin.js:40:4)
    at Compiler.applyPluginsAsync (/Users/user/project/node_modules/tapable/lib/Tapable.js:71:13)
    at Compiler.<anonymous> (/Users/user/project/node_modules/webpack/lib/Compiler.js:400:9)
    at Compilation.<anonymous> (/Users/user/project/node_modules/webpack/lib/Compilation.js:577:13)
    at Compilation.next (/Users/user/project/node_modules/tapable/lib/Tapable.js:67:11)
    at Compilation.<anonymous> (/Users/user/project/node_modules/webpack/lib/ProgressPlugin.js:69:5)
    at Compilation.applyPluginsAsync (/Users/user/project/node_modules/tapable/lib/Tapable.js:71:13)
    at Compilation.<anonymous> (/Users/user/project/node_modules/webpack/lib/Compilation.js:572:10)
    at Compilation.next (/Users/user/project/node_modules/tapable/lib/Tapable.js:67:11)
    at Compilation.<anonymous> (/Users/user/project/node_modules/webpack/lib/ProgressPlugin.js:65:5)
    at Compilation.applyPluginsAsync (/Users/user/project/node_modules/tapable/lib/Tapable.js:71:13)
    at Compilation.<anonymous> (/Users/user/project/node_modules/webpack/lib/Compilation.js:567:9)
    at Compilation.applyPluginsAsync (/Users/user/project/node_modules/tapable/lib/Tapable.js:60:69)
    at Compilation.<anonymous> (/Users/user/project/node_modules/webpack/lib/Compilation.js:563:8)
    at Compilation.applyPluginsAsync (/Users/user/project/node_modules/tapable/lib/Tapable.js:60:69)
    at Compilation.seal (/Users/user/project/node_modules/webpack/lib/Compilation.js:525:7)
    at Compiler.<anonymous> (/Users/user/project/node_modules/webpack/lib/Compiler.js:397:15)
    at /Users/user/project/node_modules/tapable/lib/Tapable.js:103:11
    at Compilation.<anonymous> (/Users/user/project/node_modules/webpack/lib/Compilation.js:445:10)
    at /Users/user/project/node_modules/webpack/lib/Compilation.js:417:12
    at /Users/user/project/node_modules/webpack/lib/Compilation.js:332:10
    at /Users/user/project/node_modules/async/lib/async.js:52:16
    at done (/Users/user/project/node_modules/async/lib/async.js:246:17)
    at /Users/user/project/node_modules/async/lib/async.js:44:16
@andreialecu
Copy link

There is some more information about this here:
microsoft/TypeScript#6365 (comment)

@jbrantly
Copy link
Member

@andreialecu Thanks for the extra info. I'll be taking a look into this shortly.

@jbrantly
Copy link
Member

I believe I've fixed this in v0.8.0, but would be great if you could let me know if it works on your setup.

@city41
Copy link

city41 commented Jun 26, 2016

I'm hitting this problem using ts-loader 0.8.2 (with webpack 1.13.1 and typescript 1.8.10). I'm brand new to TypeScript so might be user error.

I have two projects:
fooapp -- a TypeScript webapp using webpack and ts-loader
foolib -- a node module also written in TypeScript, it compiles its TypeScript into JavaScript and d.ts files into foolib/dist

$ cd foolib
foolib$ npm link
foolib$ cd ../fooapp
fooapp$ npm link foolib
/Users/matt/dev/fooapp/node_modules/foolib -> /usr/local/opt/nvm/versions/node/v5.3.0/lib/node_modules/foolib -> /Users/matt/dev/foolib
fooapp$ webpack-dev-server --progress --profile --colors --hot --config webpack.dev.config.js

...
ERROR in .lib/dist/foolib.js
Module build failed: Error: Could not find file: '/Users/matt/dev/foolib/dist/foolib.js'.
    at getValidSourceFile (/Users/matt/dev/fooapp/node_modules/typescript/lib/typescript.js:48860:23)
    at Object.getEmitOutput (/Users/matt/dev/fooapp/node_modules/typescript/lib/typescript.js:51922:30)
    at Object.loader (/Users/matt/dev/fooapp/node_modules/ts-loader/index.js:432:34)
 @ ./src/reducers/images.ts 4:21-42

Inside images.ts I have

import foolib from "foolib";

If I stop symlinking and instead copy foolib over, everything works fine

fooapp$ npm unlink foolib
fooapp$ cp -R ../foolib ./node_modules/foolib
fooapp$ webpack-dev-server --progress --profile --colors --hot --config webpack.dev.config.js

And here my webapp works as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants