Skip to content

Commit e00afd6

Browse files
committed
fix(import): catch import error for non-ESM environments
1 parent 2f42b2b commit e00afd6

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

jq-node.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,23 @@
33
const fs = require("fs");
44
const path = require("path");
55

6-
const { url } = require("./jq-wasm.url.mjs")
6+
let metaURL = undefined;
7+
try {
8+
const { url } = require("./jq-wasm.url.mjs")
9+
metaURL = url;
10+
} catch {}
11+
712
let wasmPath = path.join(__dirname, "jq.wasm");
813

914
// If running in NextJS, we need to find the actual place that the jq.wasm is stored in static files.
1015
const nextJSBuildPath = wasmPath.match(/^.+[\\\/]\.next[\\\/]server[\\\/]/)?.[0];
11-
if (nextJSBuildPath) {
12-
const suffix = url.pathname.startsWith('/_next/') ? url.pathname.slice('/_next/'.length) : url.pathname
13-
const chunkedWasmPath = path.join(nextJSBuildPath, 'chunks', suffix)
16+
if (nextJSBuildPath && metaURL !== undefined) {
17+
const suffix = metaURL.pathname.startsWith('/_next/') ? metaURL.pathname.slice('/_next/'.length) : metaURL.pathname;
18+
const chunkedWasmPath = path.join(nextJSBuildPath, 'chunks', suffix);
1419
if (fs.existsSync(chunkedWasmPath)) {
1520
wasmPath = chunkedWasmPath;
1621
} else {
17-
wasmPath = path.join(nextJSBuildPath, suffix)
22+
wasmPath = path.join(nextJSBuildPath, suffix);
1823
}
1924
}
2025

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jq-web",
3-
"version": "0.8.4",
3+
"version": "0.8.6",
44
"description": "WebAssembly build of jq with universal compatibility (Cloudflare Workers, Node.js, Browser)",
55
"main": "jq.js",
66
"files": [

0 commit comments

Comments
 (0)