Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support being imported by Node #276

Open
amjmhs opened this issue Mar 13, 2023 · 0 comments
Open

Support being imported by Node #276

amjmhs opened this issue Mar 13, 2023 · 0 comments

Comments

@amjmhs
Copy link

amjmhs commented Mar 13, 2023

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 ?!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant