Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

[0.0.39] Build fails with "TypeError: Cannot read property 'indexOf' of undefined" #305

Closed
hayuki opened this issue Nov 3, 2016 · 10 comments

Comments

@hayuki
Copy link
Contributor

hayuki commented Nov 3, 2016

Short description of the problem:

Ever since updating to app-scripts 0.0.39 I get a TypeError: Cannot read property 'indexOf' of undefined when trying to build the project. Sometimes re-installing the latest app-scripts would "fix" the issue, but today nothing I do seems to resolve it, so I cannot build and run the app at all. I even deleted my node_modules folder and re-installed everything again - still the same issue.

What behavior are you expecting?

I'm expecting to be able to build and run the project with no problems.

Steps to reproduce:
Just a note - it seems to be random, sometimes it would work and sometimes not. Lately it's mostly the latter.

  1. Update to ionic-app-scripts 0.0.39
  2. Run ionic build or ionic run android
C:\DEV\Momentum App Ionic2\momentum-client-app-v2>ionic build

Running 'build:before' npm script before build

> [email protected] build C:\DEV\Momentum App Ionic2\momentum-client-app-v2
> ionic-app-scripts build

[09:29:40]  ionic-app-scripts 0.0.39
[09:29:40]  build prod started ...
[09:29:40]  clean started ...
[09:29:40]  clean finished in 5 ms
[09:29:40]  copy started ...
Custom copy Ahoy
[09:29:40]  ngc started ...
C:\DEV\Momentum App Ionic2\momentum-client-app-v2\node_modules\@ionic\app-scripts\dist\copy.js:120
                if (err.message.indexOf('ENOENT') > -1) {
                               ^

TypeError: Cannot read property 'indexOf' of undefined
    at C:\DEV\Momentum App Ionic2\momentum-client-app-v2\node_modules\@ionic\app-scripts\dist\copy.js:120:32
    at doneOne (C:\DEV\Momentum App Ionic2\momentum-client-app-v2\node_modules\@ionic\app-scripts\node_modules\fs-extra\lib\copy\ncp.js:237:23)
    at C:\DEV\Momentum App Ionic2\momentum-client-app-v2\node_modules\@ionic\app-scripts\node_modules\fs-extra\lib\copy\ncp.js:122:11
    at C:\DEV\Momentum App Ionic2\momentum-client-app-v2\node_modules\graceful-fs\polyfills.js:219:18
    at FSReqWrap.oncomplete (fs.js:123:15)

npm ERR! Windows_NT 10.0.10240
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "build"
npm ERR! node v6.7.0
npm ERR! npm  v3.10.3
npm ERR! code ELIFECYCLE
npm ERR! [email protected] build: `ionic-app-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] build script 'ionic-app-scripts build'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the momentumclientapp package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     ionic-app-scripts build
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs momentumclientapp
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls momentumclientapp
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\DEV\Momentum App Ionic2\momentum-client-app-v2\npm-debug.log
Caught exception:
 undefined

Which @ionic/app-scripts version are you using?
latest - 0.0.39

Dev environment info:

Cordova CLI: 6.2.0
Gulp version: CLI version 3.9.1
Gulp local:
Ionic Framework Version: 2.0.0-rc.1
Ionic CLI Version: 2.1.4
Ionic App Lib Version: 2.1.2
Ionic App Scripts Version: 0.0.39
OS:
Node Version: v6.7.0

Any help would be really appreciated!

@hayuki hayuki changed the title Build fails with "TypeError: Cannot read property 'indexOf' of undefined" - app-scripts v0.0.39 [0.0.39] Build fails with "TypeError: Cannot read property 'indexOf' of undefined" Nov 3, 2016
@ynzenu
Copy link

ynzenu commented Nov 3, 2016

I have the same issue. A quick fix is to delete all the files in your www folder. But you will have to do this every time you build.

@hayuki
Copy link
Contributor Author

hayuki commented Nov 3, 2016

That's what my colleagues are also saying. But in my case, I deleted my node modules, .tmp and the www folders, did a fresh npm install, and still nothing! Still the same error :(

@ynzenu
Copy link

ynzenu commented Nov 3, 2016

Do you have any idea why Custom copy Ahoy shows up in your console? I don't have that.

@hayuki
Copy link
Contributor Author

hayuki commented Nov 3, 2016

The reason for this is that we've overridden the default copy config from ionic, to include extra data, and we added the console output to make sure it does get used:

console.log('Custom copy Ahoy');
var childProcess = require('child_process');
var copyConfig = require('@ionic/app-scripts/config/copy.config');

// instead of overriding the complete copy.config, we only add what we need
copyConfig.include.push({
  src: '{{SRC}}/environments/',
  dest: '{{TMP}}/environments/'
});

@hayuki
Copy link
Contributor Author

hayuki commented Nov 3, 2016

Hmmm... Now that you've brought my attention to this, I did some investigations. Firstly, I went to line 120 of copy.js where the error seemed to be thrown - it is a null-pointer caused by an internal error that is not handled properly. But the fact that an error was thrown was alarming as well. My colleague and I printed the error out and it was caused by our custom config stuff - when we pushed the new data into the config we specified the destination as TMP instead of WWW.

Boom! Now it works. But I think I might create a pull request to fix the null-pointer... :)

Thanks for pointing me to the right direction!

@hayuki hayuki closed this as completed Nov 3, 2016
@hayuki hayuki reopened this Nov 3, 2016
@hayuki
Copy link
Contributor Author

hayuki commented Nov 3, 2016

Not sure if I should keep this issue open...

@ynzenu
Copy link

ynzenu commented Nov 3, 2016

Glad to hear you resolved the issue. Please do pull request it so I can use it. 👍

@jgw96
Copy link
Contributor

jgw96 commented Nov 3, 2016

Hello @hayuki , thanks for all the debugging and thanks for the PR! We will take a look at it.

@jgw96
Copy link
Contributor

jgw96 commented Nov 3, 2016

Hello again! Since we merged the PR to fix this issue I am now going to close this bug. Thanks alot!

@jgw96 jgw96 closed this as completed Nov 3, 2016
@hayuki
Copy link
Contributor Author

hayuki commented Nov 3, 2016

Thanks @jgw96 !

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

No branches or pull requests

3 participants