-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Description
i am trying to use my own custom jsx factory
i had it working, but now when i try and import another library, i get this error:
file:///Users/jdion84/Sites/bas-framework/private/server.js:12
throw Error('Dynamic require of "' + x2 + '" is not supported');
^
Error: Dynamic require of "path" is not supported
at file:///Users/jdion84/Sites/bas-framework/private/server.js:12:9
at node_modules/jsdom/lib/api.js (file:///Users/jdion84/Sites/bas-framework/private/server.js:135415:16)
at __require2 (file:///Users/jdion84/Sites/bas-framework/private/server.js:18:50)
at my_modules/hydro/src/functions/jsx.js (file:///Users/jdion84/Sites/bas-framework/private/server.js:135682:28)
at __init (file:///Users/jdion84/Sites/bas-framework/private/server.js:15:56)
at file:///Users/jdion84/Sites/bas-framework/private/server.js:136607:1
at ModuleJob.run (node:internal/modules/esm/module_job:192:25)
at async DefaultModuleLoader.import (node:internal/modules/esm/loader:228:24)
at async loadESM (node:internal/process/esm_loader:40:7)
at async handleMainPromise (node:internal/modules/run_main:66:12)
Node.js v20.4.0
here is my build.js
script:
import * as esbuild from 'esbuild'
await esbuild.build({
entryPoints: ['node_modules/hydro/src/entries/server.js'],
bundle: true,
outfile: 'private/server.js',
format: 'esm',
loader: { '.js': 'jsx' },
platform: 'node',
jsxFactory: 'jsx',
inject: ['node_modules/hydro/src/functions/jsx.js'],
})
here is how i run it via package.json
scripts:
{
"scripts": {
"build": "node node_modules/hydro/src/entries/build.js",
"serve": "node private/server.js",
"dev": "npm run build && npm run serve"
},
}
just fyi, hydro
is the name of a symlinked custom package im working on
here is my factory function inside jsx.js
:
import { JSDOM } from 'jsdom'
export function jsx(tag, attributes, ...children) {
console.log(tag)
console.log(attributes)
console.log(children)
const dom = new JSDOM
const element = dom.window.document.createElement(tag)
if (attributes) {
for (const [key, value] of Object.entries(attributes)) {
element.setAttribute(key, value)
}
}
return '<b>test</b>'
}
if i remove JSDOM entirely, it works again, eg:
export function jsx(tag, attributes, ...children) {
console.log(tag)
console.log(attributes)
console.log(children)
return '<b>test</b>'
}
but i need JSDOM to work because i can't use document
in node context
how do i make my custom jsx factory work with its own imports etc.?
also, am i configuring the custom jsx factory correctly here?
Metadata
Metadata
Assignees
Labels
No labels