New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Npm module gives errors #29240

Closed
ansibot opened this Issue Sep 10, 2017 · 17 comments

Comments

Projects
None yet
10 participants
@ansibot
Copy link
Contributor

ansibot commented Sep 10, 2017

From @frenkel on 2015-11-09T14:01:08Z

ISSUE TYPE

Bug Report

COMPONENT NAME

npm module

ANSIBLE VERSION
ansible 2.2.0 (devel 3d7a7c1612) last updated 2016/07/08 22:07:24 (GMT +300)
SUMMARY

I have this role:

- name: install node-sass, grunt, grunt-cli
  npm:
    executable: /usr/local/bin/npm
    global: true
    name: '{{ item }}'
    state: present
  with_items:
    - node-sass
    - grunt
    - grunt-cli

Using latest ansible 1.9-stable branch, Node 5.0.0 or Node 0.10.4 I get these errors on some Mac OS systems:

failed: [xxx] => (item=node-sass) => {"failed": true, "item": "node-sass", "parsed": false}
Traceback (most recent call last):
  File "/Users/xxx/.ansible/tmp/ansible-tmp-1447077541.45-221529250369756/npm", line 1876, in <module>
    main()
  File "/Users/xxx/.ansible/tmp/ansible-tmp-1447077541.45-221529250369756/npm", line 244, in main
    installed, missing = npm.list()
  File "/Users/xxx/.ansible/tmp/ansible-tmp-1447077541.45-221529250369756/npm", line 168, in list
    data = json.loads(self._exec(cmd, True, False))
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 338
, in loads
    return _default_decoder.decode(s)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 366,
 in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 384,
 in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

What am I doing wrong?

Copied from original issue: ansible/ansible-modules-extras#1224

@ansibot

This comment has been minimized.

Copy link
Contributor Author

ansibot commented Sep 10, 2017

From @frenkel on 2015-11-09T14:01:08Z

Btw, manually running npm install node-sass grunt grunt-cli installs without problems. Also running npm list --json doesn't seem to give wrong output.

@ansibot

This comment has been minimized.

Copy link
Contributor Author

ansibot commented Sep 10, 2017

From @frenkel on 2015-11-09T14:01:08Z

[module: packaging/language/npm.py]

@ansibot

This comment has been minimized.

Copy link
Contributor Author

ansibot commented Sep 10, 2017

From @frenkel on 2015-11-09T14:01:08Z

@frenkel -- Thanks for submitting this bug report.

@chrishoffman -- thanks in advance for taking a look at this bug report and for your ongoing work in maintaining this module.

@ansibot

This comment has been minimized.

Copy link
Contributor Author

ansibot commented Sep 10, 2017

From @frenkel on 2015-11-09T14:01:08Z

This issue seems to affect me as well for both:

- name: Upgrade npm
  npm:
    name: npm
    global: yes
    state: latest
    executable: "{{ node_path }}/npm"

and:

- name: Install npm requirements
  npm:
    path: "{{ conf.host_path }}/{{ project }}"
    state: latest
    executable: "{{ node_path }}/npm"

Traceback:

"module_stdout": "Traceback (most recent call last):
  File \"/tmp/ansible_Fudjxb/ansible_module_npm.py\", line 268, in <module>
    main()
  File \"/tmp/ansible_Fudjxb/ansible_module_npm.py\", line 253, in main
    installed, missing = npm.list()
  File \"/tmp/ansible_Fudjxb/ansible_module_npm.py\", line 172, in list
    data = json.loads(self._exec(cmd, True, False))
  File \"/usr/lib/python2.7/json/__init__.py\", line 326, in loads
    return _default_decoder.decode(s)
  File \"/usr/lib/python2.7/json/decoder.py\", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File \"/usr/lib/python2.7/json/decoder.py\", line 384, in raw_decode
    raise ValueError(\"No JSON object could be decoded\")
ValueError: No JSON object could be decoded

Ansible version:

ansible 2.2.0 (devel 3d7a7c1612) last updated 2016/07/08 22:07:24 (GMT +300)
@ansibot

This comment has been minimized.

Copy link
Contributor Author

ansibot commented Sep 10, 2017

From @frenkel on 2015-11-09T14:01:08Z

Up. I've reproduced this situation

@ansibot

This comment has been minimized.

Copy link
Contributor Author

ansibot commented Sep 10, 2017

From @frenkel on 2015-11-09T14:01:08Z

Fails here too, same example. Only workaround is to manually run npm install for now?

@ansibot

This comment has been minimized.

Copy link
Contributor Author

ansibot commented Sep 10, 2017

@ansibot Greetings! Thanks for taking the time to open this issue. In order for the community to handle your issue effectively, we need a bit more information.

Here are the items we could not find in your description:

  • issue type
  • ansible version
  • component name

Please set the description of this issue with this template:
https://raw.githubusercontent.com/ansible/ansible/devel/.github/ISSUE_TEMPLATE.md

click here for bot help

@rockholla

This comment has been minimized.

Copy link

rockholla commented Oct 5, 2017

Also ran into this using the following:

- name: Get npm executable path
  shell: >
    . ~/.nvm/nvm.sh && which npm
  register: which_npm
  changed_when: false

- name: Ensure configured npm packages are installed globally
  npm:
    executable: "{{ which_npm.stdout }}"
    global: yes
    name: "{{ item }}"
  with_items: "{{ node_npm_global_packages }}"

Here's a workaround that seems to be going pretty well for me so far:

- name: Ensure configured npm packages are installed globally
  shell: >
    . ~/.nvm/nvm.sh && ((npm list -g | grep " {{ ('@' in item) | ternary(item,item + '@*') }}") || (npm install -g {{ item }} && echo "node-global-package-installed"))
  with_items: "{{ node_npm_global_packages }}"
  register: node_npm_global_package_install
  changed_when: "'node-global-package-installed' in node_npm_global_package_install.stdout"
  failed_when: "'npm ERR!' in node_npm_global_package_install.stderr"
@bertramn

This comment has been minimized.

Copy link

bertramn commented Nov 13, 2017

Seems to be related to the setting of the environment. It fails when using executable but the below works fine:

- name: Install Yarn
  npm:
    name: yarn
    global: yes
    production: yes
    state: latest
    #executable: "{{ node_home }}/bin/npm" << does not work
  environment:
    PATH: "{{ node_home }}/bin:{{ ansible_env.PATH }}"

ChrisOgden added a commit to ChrisOgden/ansible-nvm that referenced this issue Dec 21, 2017

@ansibot

This comment has been minimized.

Copy link
Contributor Author

ansibot commented Jan 24, 2018

@xcambar

This comment has been minimized.

Copy link
Contributor

xcambar commented Jan 29, 2018

Hi,
Can the issue be reproduced with a recent ansible (2.4 or devel)?

As the new maintainer of the npm module, I am flooded by year-old issues. So as a triage strategy, any silent issue will be closed after 10 days unless you confirm your issue still exists in recent versions.

@xcambar

This comment has been minimized.

Copy link
Contributor

xcambar commented Feb 8, 2018

Closing for lack of response.

close_me

@ansibot ansibot closed this Feb 8, 2018

@ansibot ansibot added bug and removed bug_report labels Mar 7, 2018

@ingnil

This comment has been minimized.

Copy link

ingnil commented Mar 15, 2018

I can reproduce the bug using a devel version (HEAD cloned today). Task and output follows:

- name: Install Node package Mochito
  become: true
  npm:
    name: mochito
    global: yes
    executable: /usr/local/bin/npm

Output:

Traceback (most recent call last):
  File "/tmp/ansible_wHfn0w/ansible_module_npm.py", line 291, in <module>
    main()
  File "/tmp/ansible_wHfn0w/ansible_module_npm.py", line 268, in main
    installed, missing = npm.list()
  File "/tmp/ansible_wHfn0w/ansible_module_npm.py", line 192, in list
    data = json.loads(self._exec(cmd, True, False))
  File "/usr/lib64/python2.7/json/__init__.py", line 339, in loads
    return _default_decoder.decode(s)
  File "/usr/lib64/python2.7/json/decoder.py", line 364, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib64/python2.7/json/decoder.py", line 382, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

On the other hand, just like for bertramn, if I change the task to below, it works fine:

- name: Install Node package Mochito
  become: true
  npm:
    name: mochito
    global: yes
#    executable: /usr/local/bin/npm
  environment:
    PATH: "/usr/local/bin:{{ ansible_env.PATH }}"
@eugenetaranov

This comment has been minimized.

Copy link

eugenetaranov commented Apr 7, 2018

me too, version 2.4.2.0
@xcambar could you please reopen the ticket?

@fabiel-leon

This comment has been minimized.

Copy link

fabiel-leon commented May 11, 2018

tha same issue with ansible version 2.4.3.0

- name: Install forever node.js package globally.
  npm:
    name: "{{ item }}"
    global: yes
    executable: "{{ nvm_root }}/versions/node/{{ node_version }}/bin/npm"
  with_items:
    - forever
@curiousercreative

This comment has been minimized.

Copy link

curiousercreative commented Nov 21, 2018

This task failed for me with similar error
Ansible: 2.7.1
macOS: 10.13.6 (17G3025)
Python: 3.7.1
NodeJS: 8.10.0

- name: Install gulp-cli globablly
  npm:
    name: gulp-cli
    global: yes

After some debugging, this was traced back to a wonky install of npm itself. Try uninstalling node/npm and reinstalling and/or trying some tips here specifically the brew doctor && brew prune for Mac users.

@kingfai

This comment has been minimized.

Copy link

kingfai commented Jan 11, 2019

In case anyone else stumbles into this, the solution by @bertramn worked for me too. I'm installing onto macOS 10.14.1 (Mojave).

Even calling npm via command or shell didn't work as I got the error 'env: node: No such file or directory' even though I verified that node was in /usr/local/bin.

Adding /usr/local/bin to the path as @bertramn did the trick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment