Skip to content
This repository has been archived by the owner on Aug 7, 2021. It is now read-only.

Error: Cannot find module 'node_modules\nativescript\bin\tns' #214

Closed
joey0xx opened this issue Jul 7, 2017 · 14 comments · Fixed by #218
Closed

Error: Cannot find module 'node_modules\nativescript\bin\tns' #214

joey0xx opened this issue Jul 7, 2017 · 14 comments · Fixed by #218
Assignees
Labels

Comments

@joey0xx
Copy link

joey0xx commented Jul 7, 2017

Hello, this is my first time working with Webpack.

When running npm run start-android-bundle I get the following error:

Running tns prepare...
module.js:471
    throw err;
    ^

Error: Cannot find module 'C:\Users\Angel\Documents\NativeScript\WebpackTest\node_modules\nativescript\bin\tns'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:390:7)
    at startup (bootstrap_node.js:150:9)
    at bootstrap_node.js:505:3
child process exited with code 1
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ ns-bundle: `ns-bundle`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ ns-bundle script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Angel\AppData\Roaming\npm-cache\_logs\2017-07-07T22_11_28_101Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ start-android-bundle: `npm run ns-bundle --android --run-app`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ start-android-bundle script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Angel\AppData\Roaming\npm-cache\_logs\2017-07-07T22_11_28_123Z-debug.log

The following is the package.json:

"dependencies": {
    "@angular/animations": "~4.1.0",
    "@angular/common": "~4.1.0",
    "@angular/compiler": "~4.1.0",
    "@angular/core": "~4.1.0",
    "@angular/forms": "~4.1.0",
    "@angular/http": "~4.1.0",
    "@angular/platform-browser": "~4.1.0",
    "@angular/router": "~4.1.0",
    "nativescript-angular": "~3.1.0",
    "nativescript-theme-core": "~1.0.2",
    "reflect-metadata": "~0.1.8",
    "rxjs": "~5.3.0",
    "tns-core-modules": "~3.1.0",
    "zone.js": "~0.8.2"
  },
  "devDependencies": {
    "@angular/compiler-cli": "~4.1.0",
    "@ngtools/webpack": "~1.4.0",
    "babel-traverse": "6.4.5",
    "babel-types": "6.4.5",
    "babylon": "6.4.5",
    "copy-webpack-plugin": "~4.0.1",
    "extract-text-webpack-plugin": "~2.1.0",
    "lazy": "1.0.11",
    "nativescript-css-loader": "~0.26.0",
    "nativescript-dev-typescript": "~0.5.0",
    "nativescript-dev-webpack": "^0.7.2",
    "raw-loader": "~0.5.1",
    "resolve-url-loader": "~2.0.2",
    "typescript": "~2.2.1",
    "webpack": "~3.0.0",
    "webpack-bundle-analyzer": "^2.8.2",
    "webpack-sources": "~1.0.1"
  },
  "scripts": {
    "ns-bundle": "ns-bundle",
    "start-android-bundle": "npm run ns-bundle --android --run-app",
    "start-ios-bundle": "npm run ns-bundle --ios --run-app",
    "build-android-bundle": "npm run ns-bundle --android --build-app",
    "build-ios-bundle": "npm run ns-bundle --ios --build-app",
    "publish-ios-bundle": "npm run ns-bundle --ios --publish-app",
    "generate-android-snapshot": "generate-android-snapshot --targetArchs arm,ia32 --install"
  }

That's on a new test project I created because on the project I was originally working I was getting the same error.

@sis0k0
Copy link
Contributor

sis0k0 commented Jul 8, 2017

Hey @joey0xx,

What are your versions of npm and tns?

npm --version
tns --version

@behi1ty
Copy link

behi1ty commented Jul 8, 2017

tns --version : 3.1.2
ng --version : 1.2.0
tsc --version : 2.4.1
node --version : 7.9.0
npm --version : 5.1.0
webpack version : 0.7.2

@joey0xx
Copy link
Author

joey0xx commented Jul 8, 2017

@sis0k0

npm --version: 4.6.1
tns --version: 3.1.2

@sis0k0
Copy link
Contributor

sis0k0 commented Jul 8, 2017

Hey guys, I can't reproduce the problem on Linux but I'll try later on mac/windows. Meanwhile, I can only give a few suggestions - try to downgrade the versions of nativescript-dev-webpack to 0.7.1 and nativescript-cli to 3.1.1 (npm i -g nativescript@3.1.1 for the last one)

@berchik
Copy link

berchik commented Jul 8, 2017

There seem to be a problem with nativescript webpack 0.7.2. Set your devDependencies with 0.7.1 (no ^ or ~ to maintain the exact version) like this:
"nativescript-dev-webpack": "0.7.1"

Its best to delete the modules and npm cache and then 'npm i' to have a clean install. This should solve the error you're getting.

@irvelervel
Copy link

irvelervel commented Jul 8, 2017

Getting the same error with nativescript-dev-webpack 0.7.1 and 0.7.0.

npm --version: 4.2.0
tns --version: 3.1.1

I think this issue is just Windows related, on my mac nativescript-dev-webpack 0.7.2 works perfectly.

edit: nevermind, I solved with the instructions above. Thank you!

@joey0xx
Copy link
Author

joey0xx commented Jul 10, 2017

I tried what @sis0k0 and @berchik said and I got past the error, but now I'm getting this error:

Running webpack for android...
'webpack' is not recognized as an internal or external command,
operable program or batch file.
child process exited with code 1
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! groceries@1.0.0 ns-bundle: `ns-bundle`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the groceries@1.0.0 ns-bundle script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Angel\AppData\Roaming\npm-cache\_logs\2017-07-09T23_08_59_779Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! groceries@1.0.0 start-android-bundle: `npm run ns-bundle --android --run-app`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the groceries@1.0.0 start-android-bundle script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Angel\AppData\Roaming\npm-cache\_logs\2017-07-09T23_08_59_811Z-debug.log

I googled that error and found some posts saying that I have to installl webpack globally, but when I try it by running npm install webpack -g I get the following error:

npm ERR! code ETIMEDOUT
npm ERR! errno ETIMEDOUT
npm ERR! syscall connect
npm ERR! network connect ETIMEDOUT 151.101.4.162:443
npm ERR! network This is most likely not a problem with npm itself
npm ERR! network and is related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly.  See: 'npm help config'

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Angel\AppData\Roaming\npm-cache\_logs\2017-07-10T00_01_58_123Z-debug.log

@berchik
Copy link

berchik commented Jul 10, 2017

Webpack should not be installed globally, this is not the reason for this error, I suggest you remove it. There are few things that keep bringing up errors like this; I’ll try to point out few things that seem to cause endless time-waste:

  1. Use NPM version 3.10.10. I’ve been using v5.0.4 and wasted hours with strange errors until it was suggested by @Nickliev: Webpack/ng project fails with NS3.1.1 NativeScript#4478 (comment)

  2. There are some strange issues related to the tendency of vscode to lock files. So, if this is the ide you’re using, you can solve some npm/node install problems by existing the ide and working with powershell box alone, and go back to the ide once finished installing all you need.

  3. I had a problem that was eventually solved when I’ve turn off windows defender. So you might try to shut real-time and cloud-base protection when nothing else seems to work. I would add Dropbox too, in case you’re working in the Dropbox folder.

  4. Open task manager and end all the aapt.exe, you might see plenty (or not). They also prevent deleting/installing packages.

  5. It is also a good practice to see that all the dependencies in your package.json match. It might already be set correctly in your case since you’ve already managed to start working.

These are the steps you should currently follow:

  • Shut down vscode if its open.
  • Erase node_modules, remove platforms and hooks folders.
  • Npm cache clean.
  • Make sure you have npm 3.10.10. Downgrade if you have a higher version.
  • Run ‘npm i’ from your project directory to install all the node modules.
  • add platforms.
  • Run tns android/ios build
  • Open your ide

I believe this will put you back on track.
Have fun.

@dvdbrk
Copy link

dvdbrk commented Jul 10, 2017

@berchik Thanks. Been banging my head for days now, but unfortunately your solution does not work on Windows (tsc 2.4.1, tns 3.1.1, npm 3.10.10, node 6.11.0, webpack 0.7.0)

@berchik
Copy link

berchik commented Jul 10, 2017

@dvdbrk it works ok on my windows 10/64. I use tsc 2.2.1 and ns-webpack 0.7.1, but you have to make sure all of the dependencies versions match. it'll be better if you'll attach your package.json so I can look at it.

@dvdbrk
Copy link

dvdbrk commented Jul 10, 2017

My bad!

Yes, your steps and the combination of versions I have posted above do work. My issue was ~0.7.1 in the version ( I had no idea that would not install 0.7.1, but 0.7.2 which does not work).

@berchik
Copy link

berchik commented Jul 10, 2017

Very good.
Yes, the '~' is the semantic versioning allowing automatic patch-version updates (1.0.X).

@newapx
Copy link

newapx commented Jul 11, 2017

Windows 10.

I solved the problem only downgrade nativescript-dev-webpack@0.7.2 to version 0.7.1
npm i nativescript-dev-webpack@0.7.1

@NickIliev NickIliev added bug and removed T:Question labels Jul 11, 2017
@NickIliev
Copy link
Contributor

Confirming this as a reproducible issue - test project available on my Windows environment @sis0k0

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
8 participants