Nativescript-cli: node module date-fns won't work

Created on 5 Jul 2018  路  13Comments  路  Source: NativeScript/nativescript-cli

the node module date-fns won't work with NativeScript. This module as _lib folder which seems to be ignored by NativeScript causing a:

Failed to find module: "../_lib/toInteger/index.js", relative to: app/tns_modules/date-fns/addDays/
question

Most helpful comment

@NickIliev I can confirm that it happen with 1.29.0. That version does not have a _lib directory

All 13 comments

@farfromrefug it seems that the linked package is not an official NativeScript plugin so there are no guarantees that it will build/work as expected in a NativeScript application.

You could try to "nodeify" the package via this plugin or perhaps use an alternative like moment.js (which is working with NativeScript)

@NickIliev well I agree it not a NativeScript plugin however it should work as it is and it does using webpack. It's like moment.
The issue is that for some reason "_lib" folders are ignored in node_modules and not packaged with then app.
So consequently it seems like a Nativescript build issue which could be solved. Don't you think?

EDIT: this node module does not have any "node" dependency! It only uses Date
EDIT2: nodefiy won't solve the issue

@farfromrefug I've created this test project and in fact, I was able to use the library with no issues so far.

@NickIliev thanks for creating this. I really don't understand why it does not work here. I can clearly see that the _lib folder is not packaged.

Also I saw something, I am not usingdate-fns 1.29.0 but 2.0.0-alpha11. I will try to see if they changed the module directory structure. That could be why you can't reproduce it.

Thanks again for testing this. Will report here

@NickIliev I can confirm that it happen with 1.29.0. That version does not have a _lib directory

@farfromrefug I've installed the latest official version. I haven't even noticed that there is a 2.00-alpha one. I guess it is still not production ready version so we could stick around 1.29.0 for now.

@NickIliev can't stick with 1.29.0, they added too many functions that I need ;) Did you manage to reproduce the issue with 2.0.0 ?

@farfromrefug haven't tried with 2.0.0 as the officially released one on NPM is 1.2.9.

@NickIliev so what does it mean? Do you want me to prepare a sample project with 2.0.0? You don't want to look at the issue behind because it happens with a package being noted as alpha?

@farfromrefug I've just retested with the alpha version and it is working as expected on my side. I've used v2.0.0.alpha1

I am not fond of testing an alpha version of third-party projects as these are still in development and their implementation may be changed in the final stage. However, providing a sample project is always a good practice as noted in the "New Issue" template

Please tell us how to recreate the issue in as much detail as possible.

Is there code involved? If so, please share the minimal amount of code needed to recreate the problem.

Consider using the playground to provide the code you have issues with.

@NickIliev Actually I think the sample you have is enough. Now I am seeing it randomly when running tns run android. It seems like sometimes the _lib folder is ignored. All other folders are there.
Obviously as it is random you can't really look at this. I get that. Will try to fix it myself

Thanks

@farfromrefug: did you find a way to fix that?
thank you for getting back to me about that!

@vincentpalita i have no fix for that. well I have a workaround. with web pack there is no issue as web pack handles the import 馃槈

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Fatme picture Fatme  路  3Comments

ZMW9 picture ZMW9  路  3Comments

Fatme picture Fatme  路  3Comments

DimitarTachev picture DimitarTachev  路  3Comments

PeterStaev picture PeterStaev  路  3Comments