2

Filter.ts, mustache.js and redux.3.5.2.js are in the same directory (/Scripts). The Filter.ts has the following code:

///<reference path="./typings/mustache.d.ts" />
import Mustache = require("mustache");
import Redux = require("redux.3.5.2");

In Visual studio code it shows an error on redux cannot find module. When I compile it it says:

Filter.ts(13,24): error TS2307: Cannot find module 'redux.3.5.2'.

So how is it able to find mustache but not redux?

I did not add a typing file yet but how would that affect importing the file? It is not yet used anywhere in code? Also removing the mustache typing does not result in typescript not finding the file.

$ ls *.js
requirejs.2.1.22.js  Filter.ts              mustache.js          redux.3.5.2.js

[Update]

Did an update of typescript:

npm install -g typescript

tsc.cmd now tells me I have Version 1.8.10

My task.json looks like:

{
    "version": "0.1.0",
    "command": "tsc.cmd",
    "isShellCommand": true,
    "showOutput": "silent",
    "problemMatcher": "$tsc"
}

and tsconfig.json looks like:

{
    "compilerOptions": {
        "target": "es5",
        "watch": true,
        "module": "amd",
        "removeComments": true,
        "sourceMap": false,
        "outDir": "."
    }
}

Now Visual studio code complains it cannot find any of my required modules and tsc.cmd complains it still cannot find module 'redux.3.5.2'. Luckily after a couple of restarts of Visual studio code those errors went away but it is still not able to find redux. I'm not sure if it cannot find the file or something in the file is causing this problem because the error does not specify what the exact problem is.

4
  • Are you using npm to install your modules? Commented Sep 5, 2016 at 8:48
  • @PelleJacobs No, I copied the content to the scripts directory. This is client script. Commented Sep 5, 2016 at 9:48
  • I would try to use npm. It just does so much for you. Also, redux provides a declaration file with its package. Commented Sep 5, 2016 at 10:10
  • @PelleJacobs Thank you for your reply. I don't think that will solve this particular problem. With or without mustache type def mustache is found. With or without redux type def it is not found. Is there such a thing as require.config for typescript? Then I can require any package by name, not based on the relative location of the current file? Commented Sep 6, 2016 at 2:15

2 Answers 2

1

So how is it able to find mustache but not redux

I can see in your code you have ///<reference path="./typings/mustache.d.ts" />. So you do have typings for mustache and hence it is found. I don't see any typings for redux in your sample, hence not found.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your reply, I can remove the typing of mustache or add the typing for redux. Same error.
Hi, I see now that the javascript file does not do anything and it's the typescript definition file that needs to be there. Today I tried to add immutable.js and had zero productivity again because TypeScript and visual studio code are complaining again. See my answer on how I think it works but I don't think anyone knows how it actually works or any documentation on it that would explain the complete brokenness of typescript in this regard.
0

The JavaScript file does not matter, put a definition file (for example: module-name.d.ts) in the root.

Now your ts file can contain the following:

///<reference path="module-name.d.ts" />
import redux = require("module-name");

In require.config you can do the following:

require.config = {
  baseUrl:settings.appRoot,
  urlArgs: "version=" + settings.version,
  paths: {
    "module-name" :   settings.appRoot + "/Scripts/SomePlace/some-module",
...

If you put the type definition in one directory (for example typings) then the ts file would look like this:

///<reference path="../typings/module-name.d.ts" />
import redux = require("typings/module-name");

If another ts file requires this module but the ts file is in another directory (let's see one deeper) then you can do the following:

///<reference path="../../typings/module-name.d.ts" />
import redux = require("typings/module-name");

Your require.config will look like:

require.config = {
  baseUrl:settings.appRoot,
  urlArgs: "version=" + settings.version,
  paths: {
    "typings/module-name" :   settings.appRoot + "/Scripts/SomePlace/some-module",
...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.