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

Path must be a string. Received null #120

Closed
firedev opened this Issue May 28, 2016 · 54 comments

Comments

Projects
None yet
@firedev
Copy link

firedev commented May 28, 2016

I am having some issues configuring phantomJS for karma:

WARN [plugin]: Error during loading "karma-phantomjs-launcher" plugin:
  Path must be a string. Received null
...

WARN [launcher]: Can not load "PhantomJS", it is not registered!
  Perhaps you are missing some plugin?

Nothing special the karma.js is pretty simple:

    plugins: [
    ...
      'karma-phantomjs-launcher',
    ],
    browsers: ['PhantomJS']
...

I have found similar question on SO but no replies.

What could go wrong? Thanks.

@firedev firedev closed this May 29, 2016

@firedev firedev reopened this May 29, 2016

@firedev

This comment has been minimized.

Copy link

firedev commented May 29, 2016

I guess it is related to the fact that I tried to use phantomjs-prebuilt. Here is what I did, installed phantomjs and added the following to karma.conf.js

process.env.PHANTOMJS_BIN = './node_modules/.bin/phantomjs'

Because it was complaining about missing PhantomJs otherwise:

[launcher]: No binary for PhantomJS browser on your platform.
  Please, set "PHANTOMJS_BIN" env variable.
@dignifiedquire

This comment has been minimized.

Copy link
Member

dignifiedquire commented May 29, 2016

If you are using phantomjs-prebuilt you should not need to set any env variables. Try removing your process.env line from the karma config.

@firedev

This comment has been minimized.

Copy link

firedev commented May 29, 2016

If I use phantomjs-prebuilt I get the error above, probably because of import { path } from 'phantomjs' or a similar construct somewhere. So I have replaced it with phantomjs but then karma complains it can't find phantomjs executable so I had to nail it down.

Just to be clear - it is working, feel free to close the issue.

@dignifiedquire

This comment has been minimized.

Copy link
Member

dignifiedquire commented May 29, 2016

okay thanks, closing this then. feel free to post any questions/issues though

@herrevilkitten

This comment has been minimized.

Copy link

herrevilkitten commented Jul 21, 2016

I just got this error. After some investigation, I found that karma-phantomjs-launcher worked with phantomjs-prebuilt "2.1.7" but not "^2.1.7". I haven't investigated any more than this, since it's working now :)

ETA: and now it just works so no clue really

@philjones88

This comment has been minimized.

Copy link

philjones88 commented Jul 25, 2016

I'm hitting the same issue. Installed globally phantomjs-prebuilt 2.1.1 and get the same error message.

@philjones88

This comment has been minimized.

Copy link

philjones88 commented Jul 25, 2016

Figuring out that phantomjs-prebuilt is path null...

$ node
> console.log(require('phantomjs-prebuilt'));
{ path: null, version: '2.1.1', cleanPath: [Function] }
undefined
>
@Yantrio

This comment has been minimized.

Copy link

Yantrio commented Aug 4, 2016

I seem to be hitting the same issue too, maybe it's worth re-opening the issue @firedev?

@evfender

This comment has been minimized.

Copy link

evfender commented Aug 5, 2016

+1 to reopen.

This works when I run my tests locally but on Jenkins it fails.

Running:
jenkins 2.16
node 6.3.1
karma 1.1.2
phantomjs-prebuilt 2.1.9

[31m05 08 2016 08:14:28.668:ERROR [plugin]: �[39mError during loading "/var/lib/jenkins/workspace/project/node_modules/karma-phantomjs-launcher" plugin:
  Path must be a string. Received null
@evfender

This comment has been minimized.

Copy link

evfender commented Aug 5, 2016

_Update:_
If I roll back karma-phantomjs-launcher to the last version I had installed (0.2.3) before upgrading to the latest, uninstall phantomjs-prebuilt and reinstall phantomjs, everything installs and tests are run in Jenkins and locally just fine.

@AngusFu

This comment has been minimized.

Copy link

AngusFu commented Aug 16, 2016

@philjones88 is right. Add require('phantomjs-prebuilt').path = './node_modules/.bin/phantomjs'; to karma.conf.js, the problem disappears. Yet another problem rises, where “PhantomJS have not captured in 60000 ms, killing”... Quite annoying... In Chinese we call such situation "hardly have one gourd been pushed under water when another bobs up(按下葫芦浮起瓢)", it means "solve one problem only to find another cropping up"...

@McGiogen

This comment has been minimized.

Copy link

McGiogen commented Sep 8, 2016

I fixed simply deleting all node_modules and calling "npm install" another time.

@grofit

This comment has been minimized.

Copy link

grofit commented Oct 3, 2016

Same issue today, just tried removing all node modules and re installing which did stop the error but as @AngusFu says I now just have PhantomJS not starting, if I check the command line phantomjs -v returns 2.1.1 and phantom prebuilt seems to be installed ok.

@recurrence

This comment has been minimized.

Copy link

recurrence commented Oct 15, 2016

Upgrading to latest phantomjs-prebuilt (2.1.13) fixed this error for me.

@moshie

This comment has been minimized.

Copy link

moshie commented Oct 29, 2016

This issue is still present needs resolving as it breaks angular testing suite :(

@AdamYee

This comment has been minimized.

Copy link

AdamYee commented Nov 4, 2016

In my case, I was running npm i --ignore-scripts on my CI build server. Locally, things worked without the --ignore-scripts. It works now in TeamCity without --ignore-scripts. I suspect that disallowing postinstall scripts to run could be the cause for some people.

@cbrwizard

This comment has been minimized.

Copy link

cbrwizard commented Nov 17, 2016

Also having this issue. Upgrading to the phantomjs-prebuilt@2.1.13 and karma-phantomjs-launcher@1.0.2 did not help. Adding a line process.env.PHANTOMJS_BIN = './node_modules/.bin/phantomjs' to karma.conf did not help either.

P.S. I am using yarn 0.17.3

Update: removing a node_modules folder and running npm install instead of yarn resolved this issue.

@gabyvs

This comment has been minimized.

Copy link

gabyvs commented Nov 17, 2016

I am facing the same issue and I am in the same path as @cbrwizard (using yarn). I didn't want to do npm install instead of yarn, because that takes forever while yarn is really quick. I also wanted to take advantage of yarn and make our CI jobs faster.

I solved it by running yarn, which would install my dependencies, then running npm install phantomjs-prebuilt, and then I can run yarn test successfully.

What I noticed is that if I just run npm install and then npm test all the tests would work, but running yarn and then yarn test would make the tests fail. I think the difference between both is that running npm install will execute the file install.js inside phantomjs-prebuilt, while, for some reason, that script is not executed when running yarn. So, by running npm install phantomjs-prebuilt after running yarn will force the execution of install.js script...

I don't know if that will be useful for you guys, but posting it here just in case it helps somebody.

@lunaryorn

This comment has been minimized.

Copy link

lunaryorn commented Nov 18, 2016

I'm saw the same issue as @cbrwizard, but was able to fix it without resorting to npm by

  1. Removing node_modules/
  2. Removing the yarn cache (~/Library/Caches/Yarn on MacOS, ~/.cache/yarn on Linux)
  3. yarn
  4. yarn test

Step 2 is crucial for whatever weird reason: Just removing node_modules was not enough.

@jeffcarbs

This comment has been minimized.

Copy link

jeffcarbs commented Nov 23, 2016

@gabyvs - your solution worked for me. However, you can avoid calling npm install by just running the install.js as a postinstall script:

"scripts": {
  // other scripts
  "postinstall": "node node_modules/phantomjs-prebuilt/install.js"
}

Now calling yarn will always run node_modules/phantomjs-prebuilt/install.js as the last step.

@bfcoder bfcoder referenced this issue Dec 3, 2016

Merged

Fix karma specs #33

blackbing added a commit to cnyes/react-taggable-input that referenced this issue Dec 15, 2016

@Leopoldthecoder Leopoldthecoder referenced this issue Dec 21, 2016

Closed

fix test after switching to yarn #1912

0 of 4 tasks complete

mraible added a commit to stormpath/stormpath-sdk-angular that referenced this issue Dec 28, 2016

@yagudaev

This comment has been minimized.

Copy link

yagudaev commented Apr 20, 2017

If you are using Karma it will swallow the exception and return a zero error code which will result in your CI build passing. Got a PR for it up karma-runner/karma#2672.

You can try using that fork by running:

yarn remove karma
yarn add nano3labs/karma.git#bail-on-load-error

Your CI should at least fail now.

@spencer-brown

This comment has been minimized.

Copy link

spencer-brown commented Apr 21, 2017

Having this same issue with yarn@0.23.2, karma-phantomjs-launcher@1.0.4, phantomjs-prebuilt@2.1.14, karma@1.6.0.

Can you please re-open this issue, @dignifiedquire ?

@SimenB

This comment has been minimized.

Copy link

SimenB commented Apr 21, 2017

#191 trying to fix this, or at least provide a better error message

@andrewchilds

This comment has been minimized.

Copy link

andrewchilds commented Apr 21, 2017

This fixed it for me:

rm -rf node_modules
yarn

¯_(ツ)_/¯

@yagudaev

This comment has been minimized.

Copy link

yagudaev commented Apr 25, 2017

Any idea why it breaks to begin with @SimenB? Is it a mis-configured CI where the binary doesn't get installed properly or at the wrong time?

@SimenB

This comment has been minimized.

Copy link

SimenB commented Apr 25, 2017

I think the issue is that the current method for finding the path (require('phantomjs-prebuilt').path) relies on a postinstall hook which for some reason isn't always ran, and/or its result isn't cached properly.

https://github.com/Medium/phantomjs/blob/750d5f32e1586fe0b34c782dd87f60cbb21e6441/lib/phantomjs.js#L14-L26

I'd guess running yarn --force (or yarn add phantomjs-prebuilt --force) instead of just yarn on CI should fix most of the issues people see. Basically force all postinstall hooks to run even if yarn thinks they're not necessary.

(or npm rebuild phantomjs-prebuilt as stated above if using npm)

@yagudaev

This comment has been minimized.

Copy link

yagudaev commented Apr 25, 2017

Thanks @SimenB added

# circle.yml
test:
  override:
    # force yarn to install phantomjs https://github.com/karma-runner/karma-phantomjs-launcher/issues/120#issuecomment-296924189
    - yarn --force
    - yarn test
    - yarn run lint

To our and using a forked version of karma@v1.3.0

yarn add nano3labs/karma.git#bail-on-load-error-1-3-0

Will report here how it works for our team. Hopefully, it will be a good enough workaround for the time being.

@StefH

This comment has been minimized.

Copy link

StefH commented May 3, 2017

@andrewchilds
This did indeed solve it (for now)...
See https://travis-ci.org/StefH/string-split-join

@SimenB

This comment has been minimized.

Copy link

SimenB commented May 4, 2017

Probably related: yarnpkg/yarn#1955

@ericjames

This comment has been minimized.

Copy link

ericjames commented May 5, 2017

@SimenB Running npm rebuild phantomjs-prebuilt solved it

@hiteshaneja

This comment has been minimized.

Copy link

hiteshaneja commented May 31, 2017

This happens when your phantomjs-prebuilt install is unable to run the install script of the package for some reason (For e.g. npm i run using --ignore-scripts flag etc.). What this install script does is install phantomjs on your machine (if not already installed) and creates a file called location.js inside the lib folder. The content of the location.js file looks something like this

module.exports.location = "C:\\dev\\phantomjs\\phantomjs-2.1.1-windows\\bin\\phantomjs.EXE"
module.exports.platform = "win32"
module.exports.arch = "x64"

phantomjs-launcher uses these properties to run phantomjs and if it is not found you see error "Path must be string"

So check if location.js exists inside the lib folder under phantomjs-prebuilt or not, if not, run

node node_modules/phantomjs-prebuilt/install.js
@andrewchilds

This comment has been minimized.

Copy link

andrewchilds commented Jul 28, 2017

Confirming that adding a - yarn --force line to our circle.yml file's test section fixed this issue for us:

test:
  override:
    # force yarn to install phantomjs
    # https://github.com/karma-runner/karma-phantomjs-launcher/issues/120
    - yarn --force
    - yarn test
@adreyfus

This comment has been minimized.

Copy link

adreyfus commented Sep 15, 2017

I had the error Error during loading "karma-phantomjs-launcher" plugin: Path must be a string. Received null, and adding phantomjs-prebuilt ^2.1.8 to the dependencies of the project resolved the problem.

bartriordan added a commit to everplans/fluxxed_up that referenced this issue Sep 30, 2017

@MrRaindrop

This comment has been minimized.

Copy link

MrRaindrop commented Oct 31, 2017

npm install phantomjs-prebuilt solved my problem with the same error message. Turns out the network breaking down caused none phantom was built in the system.

@blindenvy

This comment has been minimized.

Copy link

blindenvy commented Nov 4, 2017

Just experienced this issue recently as well. Adding dependency on "phantomjs-prebuilt": "2.1.8" resolved the issue.

@johnzhu12

This comment has been minimized.

Copy link

johnzhu12 commented Nov 23, 2017

@martynchamberlin your solution works for me.thanks..at first,I found the phantomSource is null in index.js of karma-phantom-launcher.
var phantomSource = require('phantomjs-prebuilt').path //phantomSource is null
phantomSource = phantomSource?phantomSource:"" //I add this line and the problem gone

so,just try this one: yarn add --force phantomjs-prebuilt

@krasimir

This comment has been minimized.

Copy link

krasimir commented Dec 7, 2017

Just to confirm that 2.1.8 version fixed the issue to me as well.

@ptim

This comment has been minimized.

Copy link

ptim commented Jan 26, 2018

npm rebuild phantom-prebuilt is the most satisfying solution for me, because I appreciate the progress bar. Running yarn add --force phantomjs-prebuilt appears to hang (but would probably resolve...). Thanks all for the informative thread!

I'm encountering this on OSX:

"karma-phantomjs-launcher": "^1.0.2",
"phantomjs-prebuilt": "^2.1.13",
@naganowl

This comment has been minimized.

Copy link

naganowl commented Jan 31, 2018

Ran into this problem locally with yarn and resolved it by running the following

yarn cache clean
rm -rf node_modules/
yarn install

There are similar steps that can be done with npm. I believe the root cause of this issue is a shared cache for the binary which is used/shared across multiple projects. I bring this up because I have another project that's using the binary and it appears the package cache may be having problems when switching between projects.

Seems like similar suggestions have already been stated above, figure that this might help someone in the future though!

@abngal

This comment has been minimized.

Copy link

abngal commented Mar 29, 2018

I solved it by preventing low disk space warnings/error.
It was failing on my teamcity container because my host OS has less the 3GB left warnings when phantomjs-prebuilt was being installed.
My folder node_modules/phantomjs-prebuilt/lib/ has incomplete files (due to npm install silent-fail )
Medium/phantomjs#533 (comment)

@MrChanLi2013

This comment has been minimized.

Copy link

MrChanLi2013 commented Jun 8, 2018

I use npm rebuild.It work!

@moonpatroller

This comment has been minimized.

Copy link

moonpatroller commented Sep 21, 2018

@philjones88 is right. Add require('phantomjs-prebuilt').path = './node_modules/.bin/phantomjs'; to karma.conf.js, the problem disappears. Yet another problem rises, where “PhantomJS have not captured in 60000 ms, killing”... Quite annoying... In Chinese we call such situation "hardly have one gourd been pushed under water when another bobs up(按下葫芦浮起瓢)", it means "solve one problem only to find another cropping up"...

Sounds like whack-a-mole.

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