canirequire

canirequireCommonJS › phantomjs

Is phantomjs ESM-only? Can you require() it?

Headless WebKit with JS API

Latest version 2.1.7, published Apr 7, 2016. JSON

CommonJS CommonJS — require() works on every Node.js version

phantomjs ships CommonJS only. require("phantomjs") works everywhere. import "phantomjs" also works because Node.js and Bun can import CommonJS from ES modules, but only the default export is guaranteed; named imports depend on Node's static analysis of the module.

Latest
2.1.7 (Apr 7, 2016)
Module format
CommonJS
Last CommonJS version
2.1.7
TypeScript types
@types/phantomjs
Node engines
not declared
Weekly downloads
90K
License
Apache-2.0

Deprecated: Package renamed to phantomjs-prebuilt. Please update 'phantomjs' package references to 'phantomjs-prebuilt'

Does phantomjs@2.1.7 actually load? Runtime test results

Runtime probe pending for this version. The values below are what package.json declares; they are refreshed once the probe runs.

Runtimerequire("phantomjs")import "phantomjs"
Node.js 18✓ expected✓ expected
Node.js 20✓ expected✓ expected
Node.js 22✓ expected✓ expected
Node.js 24✓ expected✓ expected
Node.js 26✓ expected✓ expected
Bun 1.4pendingpending

Install failed in our sandbox: error: install script from "phantomjs" exited with 1 The rows above show what package.json declares.

How to import phantomjs

ES modules (import)

import phantomjs from "phantomjs";

Named imports from a CommonJS package only work when Node.js can statically detect them. If a named import fails, use the default import and destructure.

CommonJS (require)

const phantomjs = require("phantomjs");

Module format by version

Derived from the type, main and exports fields of every stable release on npm (34 versions; the newest 34 shown).

VersionsFormatFirst published
0.0.1 – 2.1.7CommonJSSep 10, 2012

Frequently asked

Is phantomjs ESM-only?

phantomjs@2.1.7 is a CommonJS package. phantomjs ships CommonJS only. require("phantomjs") works everywhere. import "phantomjs" also works because Node.js and Bun can import CommonJS from ES modules, but only the default export is guaranteed; named imports depend on Node's static analysis of the module.

Can I import phantomjs with ES module syntax?

Yes. import phantomjs from "phantomjs" works in Node.js and Bun because they support importing CommonJS modules. Named imports work only when Node.js can statically detect the exports.

Does phantomjs ship TypeScript types?

Not bundled. Install the community types with "npm install -D @types/phantomjs".

Links

Other commonjs packages

Similar popularity