angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

TS2304: Cannot find name 'module'.

Open ericmccarthy7 opened this issue 10 years ago • 13 comments

Info about system & node version

OpenSUSE Leap 42.1
angular-cli: 1.0.0-beta.1
node: 5.11.0
os: linux x64

Steps taken to produce error

ng new test-app
cd test-app
gvim
ng serve

Error is via typescript when I'm editing the file app/test-app.component.ts

I can get rid of the error by including /// <reference path="../typings.d.ts" /> at the top of the file.

image

image

Using vim with https://github.com/leafgarland/typescript-vim and https://github.com/Valloric/YouCompleteMe

ericmccarthy7 avatar May 08 '16 04:05 ericmccarthy7

I can confirm this also is happening on windows in vim -- seems like a specific error to my setup.

ericmccarthy7 avatar May 08 '16 05:05 ericmccarthy7

I've seen live coding on last ng-conf where VSCode couldn't recognize the module variable too.

Namek avatar May 09 '16 08:05 Namek

module is defined you can see that here

This is probably related to issue #684 you can track the progress there, closing this issue now in favor of the other.

Brocco avatar May 11 '16 14:05 Brocco

try the following tsconfig filesGlob property : "filesGlob": [ "main.ts", "typings.d.ts", "app/**/*.ts", "!app/**/*.spec.ts" ],

iuliust avatar May 14 '16 10:05 iuliust

for atom-typescript :

"files": [
  "main.ts",
  "typings.d.ts"
],

for ng build :

"filesGlob": [
  "main.ts",
  "typings.d.ts"
]

I put them together.

"files": [
  "main.ts",
  "typings.d.ts"
],
"filesGlob": [
  "main.ts",
  "typings.d.ts",
  "app/**/*.ts"  
]

That works for me.

ghost avatar Jul 19 '16 06:07 ghost

@zetalei I followed your above example, but my atom-typescript still chokes on moduleId: module.id I have types installed via npm

Yugloocamai avatar Jan 20 '17 01:01 Yugloocamai

I found that if I add a reference to my top-level .ts file it works /// <reference path="../../node_modules/@types/node/index.d.ts" />

Yugloocamai avatar Jan 20 '17 01:01 Yugloocamai

I've tortured myself over this for hours now. All the suggested fixes suggest typeRoots, but I figured that all these fancy tools were smart enough to find the correct directory for "@types". Does not turn out to be the case. For those of you having this issue, make sure to include "typeRoots": [ "../node_modules/@types/" ] in your tsconfig.app.json file.

SirLants avatar Mar 06 '17 01:03 SirLants

With a brand new project I created today, I had to remove "types": [] from src/tsconfig.app.json to fix this.

nathanosdev avatar Apr 07 '18 20:04 nathanosdev

Brand new project created today June 18th and @AnimaMundi's solution was still necessary for me

stephengardner avatar Jun 18 '18 19:06 stephengardner

Spun up a new CLI project and had to remove "types":[] from both tsconfig.app.json and tsconfig.server.json after enabling hmr.

yanbu0 avatar Oct 12 '18 19:10 yanbu0

Update December 2018, this tsconfig.app.json works:

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "baseUrl": "./",
    "module": "es2015",
    "types": ["node"]
  },
  "exclude": [
    "test.ts",
    "**/*.spec.ts"
  ]
}

stephengardner avatar Dec 12 '18 02:12 stephengardner

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.