Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
vite-plugin-iso-import
Advanced tools
Import modules isomorphically. Vite discussion for potential built-in support.
Input:
import { foo } from './client-module?client'
import { bar } from './server-module?server'
Normal build output:
import { foo } from './client-module'
SSR build output:
import { bar } from './server-module'
Install library:
$ npm i -D vite-plugin-iso-import
Add plugin to vite.config.js
:
import { isoImport } from 'vite-plugin-iso-import'
export default defineCnfig({
plugins: [isoImport()]
})
You'll get a usual JS error of the value being unreferenced/undefined. Instead, you should always wrap these environment-specific code with import.meta.env.SSR
.
?client
and ?server
loses intellisenseThe library exports a custom TypeScript plugin that fixes it. Simply update your jsconfig.json
or tsconfig.json
like so:
{
"compilerOptions": {
"plugins": [{ "name": "vite-plugin-iso-import" }]
}
}
If you're using the VSCode-bundled TypeScript version, you have to update VSCode's settings.json
with "typescript.tsserver.pluginPaths": ["."]
. (Or a path to the project that contains the node_modules
folder)
Also note that this currently does not work for Vue and Svelte files. The language services are unable to load TypeScript plugins. At the meantime, you can use this suboptimal solution for npm packages only:
// global.d.ts (or any ambient dts file)
// default export
declare module 'camelcase?client' {
import all from 'camelcase'
export = all
}
// named export
declare module 'lodash-es?server' {
import * as all from 'lodash-es'
export = all
}
// fallback
declare module '*?client'
declare module '*?server'
MIT
FAQs
Import modules isomorphically
The npm package vite-plugin-iso-import receives a total of 2,545 weekly downloads. As such, vite-plugin-iso-import popularity was classified as popular.
We found that vite-plugin-iso-import demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.