Semantic-UI: Running gulp in project folder, it looks for semantic.json in wrong path

Hi.

Let’s assume we have Semantic-UI installed in C:\projects\node_modules\semantic-ui and we specified during install that our project folder is in C:\projects\brand\web and everything else default. Then, we navigate to the semantic folder in our project and run gulp build like the installation suggests. It will throw an error like this:

Building Semantic
Cannot build files. Run "gulp install" to set-up Semantic

Trying to figure out the problem, I tried moving the semantic.json to the C:\projects folder, and it worked. So, my guess is that when we run gulp, it looks for its installation path, and then it starts from there, assuming its relative path is the installation path, so it looks for the semantic.json in the wrong place. The only working solution I found, without moving the semantic.json file out of the project folder, is copying the gulp installation to a node_modules folder inside the project folder.

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 39 (7 by maintainers)

Most upvoted comments

This issue occurs when there is a node_modules folder upstream in the directory tree during installation.

For example, if you’re trying to npm install semantic-ui --save in C:\Users\ApertureScience\Desktop\SemanticUITest but happen to have an existing node_modules folder under C:\Users\ApertureScience, then the install wizard will first ask…

Is this your project folder?
C:\Users\ApertureScience

…and then if you say no and specify the absolute path C:\Users\ApertureScience\Desktop\SemanticUITest instead, the installer will install Semantic UI in that folder, but will not create a node_modules there.

If you then try gulp build in C:\Users\ApertureScience\Desktop\SemanticUITest\semantic, you get the above error.

Hope this helps, @jlukic.

Hi, since Gulp v3.8.1 there’s process.env.INIT_CWD which is the original cwd [the CLI] was launched from.

@gaborluk during the npm install semantic-ui this won’t help, and you’ll need to specify your project path manually, BUT when running gulp build, while process.cwd is C:\Users\ApertureScience\node_modules, process.env.INIT_CWD is set to the path you ran gulp build from. In your case that would be C:\Users\ApertureScience\Desktop\SemanticUITest\semantic.

So now the question for @jlukic is where to put this… Options:

  1. All calls to requireDotFile('semantic.json') would need as second argument process.env.INIT_CWD
  2. Change require-dot-file to default to process.env.INIT_CWD instead of path.join(__dirname, path.sep , '..'), which is a breaking change.
  3. Maybe have require-dot-file run both methods. Currently implemented one being default, with INIT_CWD as fallback?
  4. Something i didn’t think of?

So peinearydevelopment, the trick to change the line to userConfig = requireDotFile('semantic.json', __dirname); isn’t enough? I like your blog by the way, well explained, but I thought there would be an easier way to solve this?

I agree, I wish there was an easier way. This was 2 years ago, so my memory is a bit fuzzy on it. I think userConfig = requireDotFile('semantic.json', __dirname); does fix it. I created a postinstall command though and the extra file, so that everyone on the team doesn’t need to remember to do it when they pull down the project for the first time. Also, if your project is going to run on a build server, this will ensure that change happens there as well. All the best.

Faced the same problem. I was able to solve this problem by moving semantic.json file into my global /usr/lib/node_modules folder and that worked!