js-xss
js-xss copied to clipboard
Support being imported by Node
I was trying to use xss with Nuxt3 and server-side rendering. Unfortunately, this results in the following error during runtime:
[Vue Router warn]: uncaught error during route navigation:
file:///<project-dir>/.output/server/chunks/useCmsData-d5bab7c7.mjs:2
import { FilterXSS, getDefaultWhiteList } from 'xss';
^^^^^^^^^^^^^^^^^^^
SyntaxError: Named export 'getDefaultWhiteList' not found. The requested module 'xss' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from 'xss';
const { FilterXSS, getDefaultWhiteList } = pkg;
at ModuleJob._instantiate (node:internal/modules/esm/module_job:123:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:189:5)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:530:24)
at async file:///<project-dir>/.output/server/chunks/server.mjs:730:74
at async Object.callAsync (file:///<project-dir>/.output/server/node_modules/unctx/dist/index.mjs:53:16)
at async applyPlugin (file:///<project-dir>/.output/server/chunks/server.mjs:131:33)
at async applyPlugins (file:///<project-dir>/.output/server/chunks/server.mjs:140:5)
at async createNuxtAppServer (file:///<project-dir>/.output/server/chunks/server.mjs:6969:7)
at async Object.renderToString (file:///<project-dir>/.output/server/node_modules/vue-bundle-renderer/dist/runtime.mjs:1
Nuxt3 uses ES Modules and it seems that xss is not compatible with this. At least, during server-side rendering where it is imported by node. There is a whole documentation-page on this topic: https://nuxt.com/docs/guide/concepts/esm Including a migration-guide for third party libraries: https://nuxt.com/docs/guide/concepts/esm#library-author-guide
Can you please look into it and may adjust xss accordingly ?!