0

I built an npm module named emeraldfw and published it. My package.json file is

{
  "name": "emeraldfw",
  "version": "0.6.0",
  "bin": "./emeraldfw.js",
  "description": "Emerald Framework is a language-agnostig web development framework, designed to make developer's lives easier and fun while coding.",
  "main": "emeraldfw.js",
  "directories": {
    "example": "examples",
    "test": "test"
  },
  "scripts": {
    "test": "mocha"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/EdDeAlmeidaJr/emeraldfw.git"
  },
  "keywords": [
    "web",
    "development",
    "framework",
    "language",
    "agnostic",
    "react"
  ],
  "author": "Ed de Almeida",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/EdDeAlmeidaJr/emeraldfw/issues"
  },
  "homepage": "https://github.com/EdDeAlmeidaJr/emeraldfw#readme",
  "devDependencies": {
    "jshint": "^2.9.4",
    "mocha": "^3.3.0"
  },
  "dependencies": {
    "jsonfile": "^3.0.0",
    "react": "^15.5.4",
    "vorpal": "^1.12.0"
  }
}

As you may see, I declared a "bin": "./emeraldfw.js" binary, which corresponds to the application itself. The package.json documentations says this is going to create a link to the application executable at node.js bin/ directory. This worked fine, but when I install it globally (npm install emeraldfw -g) and then run it from the command line I receive an error messsageenter image description here

All other node modules are working fine and my application is passing in all tests and when I run it directly inside the development directory (with node emeraldfw.js) it works really fine.

I'm not a node.js expert and after having fought this error for two days, here I am to ask for help.

Any ideas?

EDIT:

I checked the permissions for my node binary (emeraldfw.js) and it belongs to edvaldo:edvaldo, my user and group. And it is with executable permissions set. I should have no permission issues inside my own area with these settings, don't you think?

8
  • Please make sure that you have installed npm as the current user instead of the administrator (sudo). You will not be able to install global packages as current user if you have installed node and npm with sudo. Also, check this link: docs.npmjs.com/getting-started/fixing-npm-permissions Commented May 17, 2017 at 3:11
  • I installed node.js (and so npm) as the current user, myself. So this should not be a problem at all. I'll check the documentation you mentioned, @AliDemirci, thanks! Commented May 17, 2017 at 3:13
  • I checked the permissions for npm, @AliDemirci, and it was installed as the current user. Commented May 17, 2017 at 3:15
  • I watched the video there and it is about permissions to install new modules with npm, which is not the case. My module installs perfectly. It is when I try to run it that I get this error, @AliPoder. Commented May 17, 2017 at 3:22
  • 1
    Glad it worked! Commented May 17, 2017 at 4:07

2 Answers 2

1

Well, shebang issue here.

Before creating npm modules, you need read every single line of it's documentation.

As it stated here you need to use shebang to let your operating system know that it should run with node instead of operating system's own script execution hosts.

Please make sure that your file(s) referenced in bin starts with #!/usr/bin/env node, otherwise the scripts are started without the node executable!

So, by using shebang on an npm module, you tell the os to create platform specific executables which let it use node to run the script. A .cmd file on Windows for example.

Sign up to request clarification or add additional context in comments.

Comments

1

Have you try to install as su?

3 Comments

Not really. Because all modules worked fine without this. And consider the fact that I am inside my own user area and node.js modules are installed in user space. This should not be neccessary at all, from my point of view.
I checked the permissions for my node binary (emeraldfw.js) and it belongs to edvaldo:edvaldo, my user and group. And it is with executable permissions set. I should have no permission issues inside my own area with these settings, don't you think?
if you want to install globally with -g, on linux and mac, I believe you have to install as su (super user).Btw your code worked, right?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.