Ts-loader: Cannot find typings with typescript@beta and @type

Created on 17 Jul 2016  ·  20Comments  ·  Source: TypeStrong/ts-loader

My problem same as in https://github.com/TypeStrong/ts-loader/issues/243

After installing @types/node i got multiple errors:

(1,21): error TS2307: Cannot find module 'fs'.
(3,23): error TS2307: Cannot find module 'path'.
(80,41): error TS2304: Cannot find name 'process'.
(5,12): error TS2304: Cannot find name 'global'.
(6,5): error TS2304: Cannot find name 'require'.

I add all definitions to types

But as said https://github.com/mhegazy in https://github.com/DefinitelyTyped/DefinitelyTyped/issues/10113#issuecomment-233199963

you should not need to add the types property, the behavior should be the same with or without it

2.0.0-beta compiler.

project: https://github.com/sanex3339/javascript-obfuscator/tree/dev

project tsconfig:

{
  "compilerOptions": {
    "target": "ES6",
    "module": "commonjs",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "noUnusedLocals": true
  }
}

entry point

"use strict";

import { JavaScriptObfuscator } from './src/JavaScriptObfuscator';

if (!(<any>global)._babelPolyfill) {
    require('babel-polyfill');
}

module.exports = JavaScriptObfuscator;

to reproduce you must clone dev branch, and run node_modules/.bin/webpack --watch

All 20 comments

I have the same issue.

I also had issues on VSCode, but they helped me to solve that by doing this: https://github.com/Microsoft/TypeScript/issues/9725#issuecomment-233793570

But this is not enough to solve ts-loader issue

As specified in #243, adding

  "compilerOptions": {
    ...
    "types": ["react", ...]
  } 

to tsconfig.json makes it work, but this should clearly not be neccessary, since tsc on itself works fine.

any update?
It is redundant to declare types in tsconfig.

I believe this is a fairly trivial fix to do, but I haven't been working on the project as the state of the tests are broken. If someone would care to improve the situation, I can work on new features.

I have a fork to support TypeScript in Vue. I have fixed most tests in TS1.8. https://github.com/HerringtonDarkholme/vue-ts-loader

I believe this is a fairly trivial fix to do

Yes, I have tried add @types support. Quite easy to implement.

But the tests are really really fragile....

Yes, the tests are a pain for me also. The implementation for ts-node is https://github.com/TypeStrong/ts-node/commit/240d4b9b751a5c551730a9856502f561844ae3b6, so it shouldn't be hard to add, but with the current state of the tests I'm hesitant to work on it without knowing I won't break something else. Hoping @jbrantly will be able to help with the situation 😄

any ideas how to fix this:

├── [email protected]
└── UNMET PEER DEPENDENCY [email protected]

@QuantumInformation Please don't fill up issues with unrelated problems. If you need help, there's Gitter, Google or a new issue.

Most likely, some package you've installed specifies a peer dependency on webpack that is different to the version you have installed.

Edit: If you did an npm ls, which it looks like you did, it probably says along the bottom what the issue is. For instance, mine says "peer dep missing: x@x, required by x@x".

@HerringtonDarkholme could you please make a PR, then the function can be merged to master branch.

I figured it out, guys.

It starts working with the following compilerOption settings:

"moduleResolution": "node",
"allowSyntheticDefaultImports": true,

@theduke setting those flags does not work for us. this still feels like a bug in ts-loader.

Any news on this? Typescript 2 is no longer in beta and typings are deprecated.

My fork has added types support, but still cannot get all tests passed. You can also have a look on awesome typescript loader.

We switched to ATL and it works fine.

Can also confirm that ATL works fine, thanks @HerringtonDarkholme for the suggestion.

Same for me. ATL just worked.

Hi @HerringtonDarkholme, (or anyone else!)

Would you be interested in submitting a PR so we could get types support into ts-loader proper? We'd be glad to get this issue resolved! BTW tests should all be passing now.

Hopefully this should be resolved by: https://github.com/TypeStrong/ts-loader/pull/318

Resolved - 🚢 with 0.9.2

Was this page helpful?
0 / 5 - 0 ratings