Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Angular] Plugin works fine in workspace, Module not found in published package #6

Closed
BlueHunter99 opened this issue Oct 2, 2020 · 11 comments

Comments

@BlueHunter99
Copy link

Issue

When building and running the plugin using the provided tools everything works. But after publishing (manually because I am on Windows) and using the plugin in another project I get the following error:

ERROR in ../node_modules/@qlip/checkbox/__ivy_ngcc__/angular/fesm2015/nativescript-checkbox-angular.js
Module not found: Error: Can't resolve '@qlip/checkbox' in 'C:\Projects\Test-Environment\barebones-checkbox-bug\node_modules\@qlip\checkbox\__ivy_ngcc__\angular\fesm2015' 
 @ ../node_modules/@qlip/checkbox/__ivy_ngcc__/angular/fesm2015/nativescript-checkbox-angular.js 4:0-42 7:34-42
 @ ./app/app.module.ts
 @ ./main.ts

Code

The troublesome code is this:

import { CheckBox } from '@qlip/checkbox';
registerElement('Checkbox', () => CheckBox);

If there is any way to change this import to make the plugin work that is preferred.

Reproduction

Workspace setup

  1. Clone https://github.com/BlueHunter99/qlip-nativescript-plugins-collection
  2. Use npm start to build the checkbox plugin and run the angular demo

Project setup

  1. ns create a new project with angular and the Hello World template, or use this demo repo
  2. ns plugin add @qlip/checkbox
  3. Add the import to app.module.ts using import { NativeScriptCheckboxModule } from "@qlip/checkbox/angular"; and add it to the imports array.
@SergeyMell
Copy link

Same issue for me (I'm on macOS)

@SergeyMell
Copy link

Actually, I have two packages in my collection https://github.com/SergeyMell/nativescript-plugins and one of them (nativescript-svg) is imported correctly to the external projects and the other one (color-wheel) works only inside the workspace demo. Tries to import it to some external project lead to the same issue as mentioned above.

@NathanWalker
Copy link
Contributor

I’m going to take a look at that repo this weekend to see what I can tell.

@NathanWalker
Copy link
Contributor

NathanWalker commented Oct 25, 2020

I setup a sample repo to consume external to plugin workspace referenced above from @SergeyMell and see the behavior as described. I'm investigating to see what may be the contributing factor in this workspace and hope to have answer by Monday.

@SergeyMell
Copy link

I managed to understand what is the source of the issue. If the plugin name does not start with nativescript- prefix the bundling process does not resolve the appropriate index.ios or index.android files. After I renamed my @sergeymell/color-wheel plugin to @sergeymell/nativescript-color-wheel it started working ok.

However, I failed to find the place where this logic is declared so I want to ask @NathanWalker if this can be considered like a bug or it is some naming conventions that we should stick to?

@NathanWalker
Copy link
Contributor

It doesn’t affect several other plugin workspaces we manage. Trying to determine what’s different about yours and qlip’s.

@SergeyMell
Copy link

Actually, I've stripped the compiled versions of both nativescript-svg and color-wheel plugins to a single package.json, index.ios.js and index.android.js files with the only one primitive function. And I was still getting the error cannot find module even if I just import it in the project like import '@sergeymell/color-wheel'. The only way after this was to assume that the issue is in naming because all other content is fully identical. I've changed the package name and it started working. Just what to emphasis, that I'm talking not about @nativescript scope but about nativescript- prefix in the plugin name inside the scope.

For sure I'll investigate more and either find some problems with qlip’s plugin or some proofs of such logic instide NativeScript bundling process

@NathanWalker
Copy link
Contributor

NathanWalker commented Oct 26, 2020

@BlueHunter99 based on @SergeyMell 's investigations this PR will get you going:
BlueHunter99/qlip-nativescript-plugins-collection#1

Nothing in tooling factors into that so could be a ng-packagr thing so we'll continue investigating but feel free to continue on this basis. It is something we do recommend with your own personal scoping to make clear those are {N} plugins under your scope and should help you manage your scope better as you can end up having other tech stack related plugins in that scope with clear identification.

Closing this for now and we'll do some other investigations outside of this regarding ng-packagr specifically.

@BlueHunter99
Copy link
Author

@NathanWalker & @SergeyMell thank you both for the investigation. Will use the PR you provided.

@dscirto
Copy link

dscirto commented Nov 5, 2020

I know this got closed but just in case it helps down the road, I was seeing the same issue and workaround that @BlueHunter99 saw. The only difference is that I was able to get a package name to work without a "nativescript-" prefix. Here's what I tried:

  • @uiwt/drop-down (failed)
  • @uiwt/nativescript-drop-down (success)
    - @hn-ns/drop-down (success)

Just thought it was interesting that the "@hn-ns" scope I used didn't require a package name starting with "nativescript-"

@abdallahkadour
Copy link

abdallahkadour commented Aug 12, 2022

I have the same issue, even if I change the plugin name so that it includes nativescript. It works in vanilla demo but in angular demo, I am still getting the error

error TS2307: Cannot find module @name-space/hello-world or its corresponding type declarations.
2 import {  } from @name-space/hello-world;

Any idea?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants