Ionic 2 - Importing from Angular2

Hi all,

feeling a bit dumb dumb :smile:

I’ve created a new file under www/app/services/test-service.ts

I’m stuck at a very simple line:

import {Http, HTTP_PROVIDERS} from ‘angular2/http’;

Getting the following error:

cannot compile modules unless the ‘–module’ flag is provided

Any idea what is happening? Thanks folks!

1 Like

It’s probably a config error in your tsconfig.json, webpack.config.js, ionic.config.js or gulpfile.js, can you put a gist to them to be able to debug a bit?

1 Like

Hey thanks for the reply!

Playing around a bit found it it raises that error for each file that is not imported anywhere (an unused file).
Once I import it then code completion and type checking starts working.

Seems to be mainly an IDE bug.

Thanks again

1 Like

Soo are you using an IDE and using it to compile the code? i use the CLI to serve and compile and in some point in time i had this error, so it shouldn’t be an issue with the IDE.

1 Like

I had the same problem as him and in my case was the tsconfig.json.

There is a parameter called files like so:

…,
“files”: [
“app/app.ts”]

or something like that. Well it was showing the whole file with green squiggly lines (VS Code) and after deleting that parameter everything worked perfectly after I restarted VS Code.

current tsconfig file:

{
“compilerOptions”: {
“target”: “es5”,
“module”: “commonjs”,
“noEmitOnError”: false,
“rootDir”: “.”,
“emitDecoratorMetadata”: true,
“experimentalDecorators”: true,
“sourceMap”: false,
“sourceRoot”: “”,
“inlineSourceMap”: false,
“inlineSources”: false
},
“exclude”: [
“node_modules”
],
“compileOnSave”: false
}

2 Likes

I had the same issue. Removing the files property seemed to do the trick for me as well. I wonder if that is needed for anything?

1 Like

@Charlie001: https://github.com/Microsoft/TypeScript/wiki/tsconfig.json#using-tsconfigjson

  • By invoking tsc with no input files, in which case the compiler searches for the tsconfig.json file starting in the current directory and continuing up the parent directory chain.

  • By invoking tsc with no input files and a -project (or just -p) command line option that specifies the path of a directory containing a tsconfig.json file.

1 Like