Skip to content
This repository has been archived by the owner on Sep 7, 2022. It is now read-only.

Path must be a string. Received null #120

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

Path must be a string. Received null #120

firedev opened this issue May 28, 2016 · 54 comments
Labels

Comments

@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 as completed May 29, 2016
@firedev firedev reopened this May 29, 2016
@firedev
Copy link
Author

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
Copy link
Member

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
Copy link
Author

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
Copy link
Member

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

@herrevilkitten
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
Copy link

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

@philjones88
Copy link

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

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

@Yantrio
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
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
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
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
Copy link

McGiogen commented Sep 8, 2016

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

@grofit
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
Copy link

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

@moshie
Copy link

moshie commented Oct 29, 2016

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

@AdamYee
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
Copy link

cbrwizard commented Nov 17, 2016

Also having this issue. Upgrading to the [email protected] and [email protected] 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
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.

@swsnr
Copy link

swsnr 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
Copy link

@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.

@yagudaev
Copy link

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
Copy link

Having this same issue with [email protected], [email protected], [email protected], [email protected].

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

@SimenB
Copy link

SimenB commented Apr 21, 2017

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

@andrewchilds
Copy link

This fixed it for me:

rm -rf node_modules
yarn

¯_(ツ)_/¯

@yagudaev
Copy link

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
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
Copy link

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 [email protected]

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
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
Copy link

SimenB commented May 4, 2017

Probably related: yarnpkg/yarn#1955

@ericjames
Copy link

@SimenB Running npm rebuild phantomjs-prebuilt solved it

@hiteshaneja
Copy link

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
Copy link

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
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.

@MrRaindrop
Copy link

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.

@jackson-chris
Copy link

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

@johnzhu12
Copy link

@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
Copy link

krasimir commented Dec 7, 2017

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

@ptim
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
Copy link

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
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
Copy link

I use npm rebuild.It work!

@moonpatroller
Copy link

@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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests