question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is it necessary to copy all modules from node_modules directory, including devDependencies?

See original GitHub issue

I have this package.json

{
    "nativescript": {
        "id": "org.nativescript.test1",
        "tns-android": {
            "version": "1.4.0"
        }
    },
    "dependencies": {
        "tns-core-modules": "1.4.0"
    },
  "devDependencies": {
    "babel": "^5.8.29",
    "gulp-debug": "^2.1.2"
  }
}

I have some devDependencies modules, and of course, after install, they are placed to node_modules. After build, all of them are copied to platforms\android\src\main\assets\app\tns_modules\. (app-debug.apk contains it too) I’m using devDependencies modules for building and testing only.

Is it really necessary to copy them all?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
rosen-vladimirovcommented, Jan 5, 2016

Hi @unlight ,

Thanks for sharing the steps to reproduce. In fact there are two different “issues” here. The first one is related to npm3 as you have noticed. It really flattens the dependencies and when we process them, we do not know if they are from dependencies or devDependencies section of any module. The issue occurs whenever you install npm package with npm i (when you are using npm 3). The workaround is to remove node_modules directory and execute your tns command, for example tns build android. One of the first steps that we execute during preparing the project is to ensure all dependencies are installed. In case you do not have node_modules directory, we’ll install the dependencies with the npm version that we have in our nativescript-cli (2.14.12 - https://github.com/NativeScript/nativescript-cli/blob/master/package.json#L57). This way all packages will be installed correctly (as we are using npm 2) and we’ll prepare them correctly in the native project. The other issue is one implementation detail in our logic - when we process node_modules we get all directories (and subdirectories and subsubdirectories, etc.) and we filter only the ones that are devDependency of any package. When a package in node_modules is not defined anywhere in any package.json, we do not filter it as it is not defined as devDependency.

Hope this makes sense for you 😃

0reactions
irwansyahwiicommented, Nov 17, 2018

I think this issue must be open again since I found out if we install npm module as a dev dependency then it won’t get copied to the tns_modules folder hence it will run error at run time. So the fix is to remove the platform and re-add it again and install the module as a runtime dependency.

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - Is it safe to copy node_modules? - Stack Overflow
In general it should be fine - I copy the node_modules directory sometimes from my other projects to speed up the setup process....
Read more >
Should I commit the node_modules folder to Git? - Flavio Copes
Not committing node_modules implies you need to list all your modules in the package.json (and package-lock.json ) as a mandatory step.
Read more >
How To Use Node.js Modules with npm and package.json
The first step will be to create and understand the package.json file. You will then use it to keep track of all the...
Read more >
Cleanup the node_modules for a lighter Lambda Function
Any nodejs project carries a bulky folder - the node_modules - that carries all the modules and dependencies that the application would need...
Read more >
Reliable Development Workflows for Local Node ...
Not all of these modules ship with the products, ... has its own node_modules directory tree (since it specifies devDependencies on React ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found