tns-template-plugin icon indicating copy to clipboard operation
tns-template-plugin copied to clipboard

Cannot find module 'nativescript-sim-card'

Open roblav96 opened this issue 8 years ago • 10 comments

I'm trying to write a simple sim-card plugin.

Once I'm done filling out the questions, I go to main-view-model.js and add:

import { SimCard } from "nativescript-sim-card";

then run npm run demo.ios and it throws:

roblav96@Roberts-iMac:/Volumes/OSX HD/Downloads/nativescript-sim-card$ npm run demo.ios

> [email protected] demo.ios /Volumes/OSX HD/Downloads/nativescript-sim-card
> npm run preparedemo && cd demo && tns emulate ios


> [email protected] preparedemo /Volumes/OSX HD/Downloads/nativescript-sim-card
> npm run build && cd demo && tns plugin remove nativescript-sim-card && tns plugin add .. && tns install


> [email protected] build /Volumes/OSX HD/Downloads/nativescript-sim-card
> tsc

unbuild [email protected]
Successfully removed plugin nativescript-sim-card for ios.

> [email protected] prepublish /Volumes/OSX HD/Downloads/nativescript-sim-card
> tsc


> [email protected] prepublish /Volumes/OSX HD/Downloads/nativescript-sim-card
> tsc

[email protected] node_modules/nativescript-sim-card
Successfully installed plugin nativescript-sim-card.

Exception: Platform ios already added
Executing before-prepare hook from /Volumes/OSX HD/Downloads/nativescript-sim-card/demo/hooks/before-prepare/nativescript-dev-typescript.js
Found peer TypeScript 1.8.10
app/main-view-model.ts(4,25): error TS2307: Cannot find module 'nativescript-sim-card'.

TypeScript compiler failed with exit code 1
Sending exception report (press Ctrl+C to stop).....

I'm trying to follow https://github.com/NathanWalker/nativescript-plugin-seed and try to copy what's going on there. I would use that one, but it doesn't work with TNS v2.2.0

roblav96 avatar Aug 16 '16 06:08 roblav96

In your actual source code file did you export a "SimCard" class? Because your import statement is attempting to import it...

NathanaelA avatar Aug 16 '16 06:08 NathanaelA

this is my sim-card.ios.ts class file:

/**********************************************************************************
 * (c) 2016, Robert Laverty.
 * Licensed under the MIT license.
 *
 * Version 1.0.0                                                    [email protected]
 **********************************************************************************/
'use strict';

export class SimCard {

    message: string = 'contructor wtf'

    constructor() {
        // Put in your initialization
        console.log("contructor wtf???");
        console.log("contructor wtf???");
        console.log("contructor wtf???");
        console.log("contructor wtf???");
    }
}

Please excuse the wtf's lol 😄

roblav96 avatar Aug 16 '16 06:08 roblav96

Can you double check that your package.json; and verify that it has "sim-card.js" as the main key?

NathanaelA avatar Aug 16 '16 06:08 NathanaelA

In the ./demo/package.json or the ./package.json?

And what do you mean by main key?

roblav96 avatar Aug 16 '16 06:08 roblav96

Here's a commit history of trying to get this working: https://github.com/roblav96/tns-template-plugin/commits/master

Commit 1

this is directly after answering all questions https://github.com/roblav96/tns-template-plugin/tree/c574f3d87d5ed13a6ccc1681ed0d05d7f9463a6d

Commit 2

this is after adding the import to main-view-model.ts https://github.com/roblav96/tns-template-plugin/commit/08a4d16b4917a33487ace3dae3ca00f795c3cd42 https://github.com/roblav96/tns-template-plugin/tree/08a4d16b4917a33487ace3dae3ca00f795c3cd42

roblav96 avatar Aug 16 '16 06:08 roblav96

Do I have to edit index.d.ts?

export * from './sim-card.ios';

like here: https://github.com/NathanWalker/nativescript-plugin-seed/blob/master/index.d.ts

roblav96 avatar Aug 16 '16 07:08 roblav96

After quite a bit of trial and error, I got it working.

I basically copy and pasted all the package.json & tsconfig.json files from https://github.com/NathanWalker/nativescript-plugin-seed

Also this might help:

roblav96@Roberts-iMac:/Volumes/OSX HD/Downloads/nativescript-sim-card$ npm run demo.ios

> [email protected] demo.ios /Volumes/OSX HD/Downloads/nativescript-sim-card
> npm run preparedemo && cd demo && tns emulate ios


> [email protected] preparedemo /Volumes/OSX HD/Downloads/nativescript-sim-card
> npm run build && cd demo && tns plugin remove nativescript-sim-card && tns plugin add .. && tns install


> [email protected] build /Volumes/OSX HD/Downloads/nativescript-sim-card
> tsc

unbuild [email protected]
Successfully removed plugin nativescript-sim-card for ios.

> [email protected] prepublish /Volumes/OSX HD/Downloads/nativescript-sim-card
> tsc


> [email protected] prepublish /Volumes/OSX HD/Downloads/nativescript-sim-card
> tsc

[email protected] node_modules/nativescript-sim-card
Successfully installed plugin nativescript-sim-card.

Exception: Platform ios already added
Executing before-prepare hook from /Volumes/OSX HD/Downloads/nativescript-sim-card/demo/hooks/before-prepare/nativescript-dev-typescript.js
Found peer TypeScript 1.8.10
app/main-view-model.ts(2,23): error TS2307: Cannot find module 'nativescript-sim-card'.

Successfully prepared plugin nativescript-sim-card for ios.
Successfully prepared plugin tns-core-modules for ios.
Successfully prepared plugin tns-core-modules-widgets for ios.
Project successfully prepared (ios)
Build settings from command line:
    ARCHS = i386 x86_64
    CODE_SIGN_IDENTITY = 
    CONFIGURATION_BUILD_DIR = /Volumes/OSX HD/Downloads/nativescript-sim-card/demo/platforms/ios/build/emulator
    ONLY_ACTIVE_ARCH = NO
    SDKROOT = iphonesimulator9.3
    SHARED_PRECOMPS_DIR = /Volumes/OSX HD/Downloads/nativescript-sim-card/demo/platforms/ios/build/sharedpch
    VALID_ARCHS = i386 x86_64

=== BUILD TARGET demo OF PROJECT demo WITH CONFIGURATION Debug ===

TLDR

app/main-view-model.ts(2,23): error TS2307: Cannot find module 'nativescript-sim-card'.
Successfully prepared plugin nativescript-sim-card for ios.

Before, after Cannot find module 'nativescript-sim-card' it would crash and not build. So it looks like there was some sort of setting I had changed that would bypass that? Idk I'm quite new to TS and NS.

roblav96 avatar Aug 16 '16 07:08 roblav96

Any updates? I really like the workflow of developing plugins with this. Would love to see this working properly.

roblav96 avatar Aug 18 '16 03:08 roblav96

Don't worry; I'll get it working soon. Just haven't had time to mess with it, yet. Paid work has to come before the free stuff...

NathanaelA avatar Aug 18 '16 03:08 NathanaelA

Yes of course! Thanks so much for all your great work :D

roblav96 avatar Aug 18 '16 04:08 roblav96