Skip to content
This repository has been archived by the owner on Jul 8, 2020. It is now read-only.

config-const.js emptied on new file with gulp watch #363

Closed
ruddell opened this issue May 1, 2016 · 19 comments
Closed

config-const.js emptied on new file with gulp watch #363

ruddell opened this issue May 1, 2016 · 19 comments

Comments

@ruddell
Copy link

ruddell commented May 1, 2016

Hey, I'm loving the generator, thank you for all of the work.

Overview of the issue

When running gulp watch, if a new file is added to the project (copied or generated), the config-const.js file is erased (all lines of the file are removed). This will then cause running the project and building the project to fail as there is no Config constant to inject.

The gulp output from the Reproduce the Error section below can be seen http://pastebin.com/raw/Dn6f8Ktw

Version(s)

1.8

Configuration file
{
  "generator-m-ionic": {
    "answers": {
      "appName": "test",
      "appId": "com.jruddell.test",
      "ionicCss": false,
      "bowerPackages": [
        "localforage#~1.4.0"
      ],
      "platforms": [],
      "plugins": [
        "cordova-plugin-device"
      ],
      "appModule": "test",
      "ecosystems": []
    }
  }
}
Reproduce the error
mkdir test && cd test
yo m-ionic
gulp watch

In new terminal tab

yo m-ionic:controller test

Also happens if you copy a file into the project instead of generating a new one.

Fix

I haven't looked into how to fix it, not the best with gulp.

@ruddell
Copy link
Author

ruddell commented May 1, 2016

Related to #227 but happens with only gulp watch

@gruppjo
Copy link
Contributor

gruppjo commented May 2, 2016

EDIT:
Hotfix: downgrade gulp-inject to 3.0.0 from 4.0.0 in your project's package.json for now


Hi @ruddell!
I couldn't reproduce your issue on my machine with our demo repository. Can you provide the following details?

# post the result of the following commands
node -v # node version
npm -v # npm version
npm list -g generator-m-ionic # generator version
  • Which OS and version are you on?
  • Please provide a Demo repository so I can check if something's wrong with your repo or something else

@ruddell
Copy link
Author

ruddell commented May 2, 2016

I can confirm that this issue does not occur on the demo project, but if you generate a project with the .yo-rc.json from my initial post, the issue is present. I also experienced it with iOS as a platform

Repo with commits at each step (.yo-rc.json, generation, initial gulp watch, and changes after generating/adding a file) https://github.com/ruddell/m-ionic-test

Program Version
Node v5.5.0
NPM v3.7.3
OS Mac
OS Version El Capitan, 10.11.4

@gruppjo
Copy link
Contributor

gruppjo commented May 2, 2016

Thank you for your very fine reporting and the nice demo repo! :)

Unfortunately I still cannot reproduce the issue. Here's what I did:

git clone git@github.com:ruddell/m-ionic-test.git
cd m-ionic-test
npm i && bower i
gulp watch

And then:

$ yo m-ionic:controller acontroller
You called the m-ionic:constant subgenerator.
You called the m-ionic:controller subgenerator.
   create app/main/controllers/acontroller-ctrl.js
   create test/karma/main/acontroller-ctrl.spec.js
$ gs
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   app/index.html

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    app/main/controllers/acontroller-ctrl.js
    test/karma/main/acontroller-ctrl.spec.js

no changes added to commit (use "git add" and/or "git commit -a")

I'd recommend deleting the node_modules folder and npm i again, but you probably tried that already, additionally this seems to occur independent from your project.

I'm out of ideas for now.

You could probably remove the environments task and the config-const files if you don't need them, but that not a very satisfying solution...

@ruddell
Copy link
Author

ruddell commented May 2, 2016

I'm sorry, I pushed the blank config file to show the flow of actions. I reversed the commit and tested the repo again (using your process from the last post) and I get the following:

Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   app/index.html
    modified:   app/main/constants/config-const.js

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    app/main/controllers/acontroller-ctrl.js
    test/karma/main/acontroller-ctrl.spec.js

no changes added to commit (use "git add" and/or "git commit -a")

@gruppjo
Copy link
Contributor

gruppjo commented May 3, 2016

Wops. Of course it didn't work then ;)

I tried again, 5 times and still I cannot reproduce.
One more idea: What's the output of:

gulp -v

Mine is:

$ gulp -v
[10:02:21] CLI version 3.9.0
[10:02:21] Local version 3.9.1

Maybe you can upgrade to the latest version?

However I noticed that sometimes the SCSS/CSS doesn't render after a new file is created. Do you get that as well?

@ruddell
Copy link
Author

ruddell commented May 3, 2016

I tested on a new ubuntu-upstart docker image and I could not reproduce the issue so it has to be something with my setup. Sorry for taking up your time, but at least we found a different issue.

It looks like the css file is deleted and not recreated, leaving the project without styling. Restarting gulp watch fixes it but I'm not sure if that's a solution.

@objectiveP
Copy link

Hey, i just wanted to let you know that I have same issue, so maybe there is something more to it. Same with the css file.

@SadiSofiane
Copy link

SadiSofiane commented May 4, 2016

Same problem for me...
In order to make it work I have to insert the default config-const.js content before running a gulp watch

'use strict';
angular.module('main')
.constant('Config', {
  // gulp environment: injects environment vars
  ENV: {
    /*inject-env*/
    /*endinject*/
  },

  // gulp build-vars: injects build vars
  BUILD: {
    /*inject-build*/
    /*endinject*/
  }

});

@objectiveP
Copy link

Are you guys using Webstorm (or whatever is based on IntelliJ) for editing? This could be the reason for the problem. My hypothesis is that is somehow an I/O issue between gulp and web storm indexing the file. I excluded the constants directory from the project scope, which fixed the problem for me.

If that is the case, it is not problem of the generator and issue can be closed.

@SadiSofiane
Copy link

I am using vim.

@gruppjo
Copy link
Contributor

gruppjo commented May 6, 2016

Everybody willing to help or experiencing this issue, please provide the following formatted as below. That way I might find a way to reproduce this (which I currently cannot) and try to fix this.

  • Do you experience this issue?
  • important: does the problem occur without running any other gulp task?
  • Which OS and version are you on?
# post the result of the following commands
node -v # node version
npm -v # npm version
npm list -g generator-m-ionic # generator version
gulp -v

For me this would be:

Info Answer
Occurs? No
Occurs without other gulp tasks? No
OS & Version Mac, El Capitan, 10.11.4
Node v5.11.0
NPM v3.8.6
Generator v1.8.0
Gulp v3.9.0

@ruddell
Copy link
Author

ruddell commented May 6, 2016

@gruppjo I believe this issue occurs when injecting into the same file more than once at the same time. See the last comment klei/gulp-inject#123

From the original post's gulp output log (seen when I reproduce the issue), two injections at the same time:

[12:15:15] gulp-inject 1 files into main/constants/config-const.js.
[12:15:15] Finished 'styles' after 1.4 s
[12:15:15] gulp-inject 1 files into main/constants/config-const.js.

In injecting.js, the environment task is called from two different places, both injecting into config-const.js. inject-all calls environment, inject-all calls build-vars which also calls environment

I'll look more into this issue this weekend. The commit I referenced this fixes it in most cases, but if you run the generator several times quickly it occasionally clears it still...

@gruppjo
Copy link
Contributor

gruppjo commented May 7, 2016

We migrated gulp-inject from 3.0.0 to 4.0.0 in the last update. I'm starting to suspect this to be the cause of the problem because it doesn't seem to have occurred before. Can anyone experiencing this issue downgrade to 3.0.0 in their package.json (https://github.com/mwaylabs/generator-m-ionic-demo/blob/master/package.json#L23) and then run npm install to confirm that the problem still occurs?

@ruddell
Copy link
Author

ruddell commented May 7, 2016

When I downgraded to 3.0.0, the issue disappears.

I still have the css get deleted like you mention. I generated foobar.ctrl.js and foobar2.ctrl.js, line 72 of the gulp log shows the css being deleted from the .tmp folder http://pastebin.com/mKrhRfsy

@gruppjo
Copy link
Contributor

gruppjo commented May 9, 2016

Thanks for verifying!
The CSS issue I don't mind so much, since it doesn't occur that often and doesn't break/delete anything. The gulp tasks need some general overhaul anyway but I'm waiting for gulp 4 to come around, since we'll have to rewrite them then anyhow.

@gruppjo
Copy link
Contributor

gruppjo commented Jun 2, 2016

@ruddell, did you have a chance to test this with gulp-inject@4.1.0?

@ruddell
Copy link
Author

ruddell commented Jun 3, 2016

I can no longer reproduce the error using gulp-inject@4.1.0.

SCSS still fails to compile occasionally

@gruppjo
Copy link
Contributor

gruppjo commented Jun 3, 2016

Nice. Thanks for your valuable input @ruddell! Then no more actions are necessary. Let's hope this issue doesn't return.
The css issue might be related to the following issue and might be fixed by this watch task modification #317 (comment). If you have the time let me know if this helps.

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

4 participants