TypedJSON: Cannot find module “.” issue with Ionic 2
Hi, I have the following issue while doing an ionic 2 serve command using TypedJSON :
Error: Cannot find module "."
at webpackMissingModule (http://localhost:8100/build/main.js:82208:69)
at METADATA_FIELD_KEY (http://localhost:8100/build/main.js:82208:147)
at Object.<anonymous> (http://localhost:8100/build/main.js:82213:3)
at __webpack_require__ (http://localhost:8100/build/main.js:20:30)
at Object.<anonymous> (http://localhost:8100/build/main.js:94414:86)
[...]
I can reproduce it with a simple app. Here are my steps :
//Installing last ionic version
npm install -g ionic@latest cordova typescript
//Creating a new app
ionic start test blank --v2
//Installing webpack support
npm install @ionic/app-scripts@latest --save-dev
//Installing TypedJSON
npm install typedjson-npm
//Installing typings
typings install npm:typedjson-npm
I created a simple model :
import { JsonMember, JsonObject } from 'typedjson-npm';
@JsonObject
export class GeoJsonModel {
@JsonMember
type: string;
public getType() {
return this.type;
}
}
And here is my home.ts
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { GeoJsonModel } from '../../models/geojson-model';
import { TypedJSON } from 'typedjson-npm';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(public navCtrl: NavController) {
var geo= TypedJSON.parse('{ "type": "geojson"}', GeoJsonModel);
console.log(geo instanceof GeoJsonModel);
console.log(geo.getType());
}
}
Based on #49 I added in tsconfig.json “module”: “commonjs” but it doesn’t seem to work. I’m probably doing something wrong.
Thank you for your help.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 15 (1 by maintainers)
Commits related to this issue
- Merge pull request #82 from harikvpy/master Fix for #79 & #57 — committed to JohnWeisz/TypedJSON by JohnWeisz 6 years ago
FYI: Visual Studio Code was putting “/umd” suffix in some auto-imports causing this error for me in an Ionic project - removed that and it was fine - see here: https://github.com/webpack/webpack/issues/4921#issuecomment-399934222
I got the same error, fixed it by importing the ts file:
import { TypedJSON, JsonObject, JsonMember } from 'typedjson-npm/src/typed-json';Maybe this should be added to the docs.
@JohnWeisz … no need to apologise at all! Thanks for the details and outlook on a new version …
I apologize for joining in this late.
Most of these issues relate to the fact that originally, TypedJSON was created simply as a client for .NET JSON serializers, and no
npmrelease was ever planned (it was actually a NuGet package). The installation you are all having problems with was later published by a generous contributor, but generosity is not a factor when it comes to doing something that was not meant to be done in the first place.However, since then I realized this is needed by many on the node platform, and thus I re-imagined the code structure of TypedJSON (with a massive amount of fixes and new features, as well), and it’s now around the clock to be released in a new version and multiple distributions, one of them meant explicitly for the
npmregistry for NodeJS and isomorphic use.Since I would now like to offer TypedJSON for more serious, non-experimental use, I’m asking for your patience until I’m ready with a comprehensive integration test suite.