V2: tutorial - cannot find module


#1

I’m trying out ionic V2, followed the getting started guide and have a working tutorial.

Next I tried to add a custom page.

ionic g page testpage

This did what it was supposed to and created app/pages/testpage/testpage.(scss | js | html)
(Q: for typescript should it generate a .ts file?)

However I can’t seem to get this page to work in the tutorial app.

In app.js

import {TestpagePage} from ‘./pages/testpage/testpage’;

// set our app’s pages
this.pages = [
{ title: ‘Hello Ionic’, component: HelloIonicPage },
{ title: ‘My First List’, component: ListPage },
{ title: ‘TestPage’, component: TestpagePage }
];

And it throws the error:

uncaught error: cannot find module ‘./pages/testpage/testpage’

I can’t see what I’m doing differently than the tutorial. The path ‘./pages/testpage/testpage’ is relative to app.(js | ts) just the same as the tutorial pages. I’ve read all the examples I can find and it all looks like it should be this easy and should work, it’s just not. Do I have a fundamental misunderstanding of something here?


#2

Did you start with a TypeScript project or a JavaScript one? Currently there is a bug in the CLI and it always generates JS files, even in TS-projects. This is an error that you’ll receive if you import JS-file in a TS-project.


#3

if you try to create a v2 with typescript you should follow steps describe bellow link


#4

I have tried both methods, I noticed that it always generates js files. I get the same error in a non-TS project. In a TS project I get the error even if I convert it to a ts file.


#5

Alright, this morning it works… no idea what’s changed. Thanks everyone.