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

> phantomjs@2.1.7 is a CommonJS package. CommonJS — require() works on every Node.js version we test.

Headless WebKit with JS API

Latest version 2.1.7, published Apr 7, 2016.

phantomjs ships CommonJS only. require("phantomjs") should work on every Node.js version the package supports; the runtime probe has not run for this version. 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.

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

## What to do

1. require("phantomjs") should work on every Node.js version the package supports; the runtime probe has not run for this version.
2. From ES modules use the default import: import phantomjs from "phantomjs"; then destructure. Named imports only work when Node.js can statically detect the exports.
3. TypeScript: npm install -D @types/phantomjs
4. This package is deprecated: Package renamed to phantomjs-prebuilt. Please update 'phantomjs' package references to 'phantomjs-prebuilt'

## Facts

- 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

## Runtime test results for phantomjs@2.1.7

Runtime probe pending for this version (install failed: error: install script from "phantomjs" exited with 1). The facts above come from package.json.

## How to import phantomjs

ES modules:

```js
import phantomjs from "phantomjs";
```

CommonJS:

```js
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).

| Versions | Format | First published |
|---|---|---|
| 0.0.1 – 2.1.7 | CommonJS | Sep 10, 2012 |

## Frequently asked

**Is phantomjs ESM-only?**

phantomjs@2.1.7 is a CommonJS package. phantomjs ships CommonJS only. require("phantomjs") should work on every Node.js version the package supports; the runtime probe has not run for this version. 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

- [phantomjs on npm](https://www.npmjs.com/package/phantomjs)
- [Source repository](https://github.com/Medium/phantomjs)
- [HTML version](https://canirequire.com/package/phantomjs/)
- [JSON version](https://canirequire.com/package/phantomjs.json)

---

For scripts and AI agents: any package is at https://canirequire.com/package/<name>/index.md (Markdown) or https://canirequire.com/package/<name>.json (JSON); the site index is https://canirequire.com/llms.txt. Fetch the URL directly; no search needed.
