Socket
Book a DemoInstallSign in
Socket

vite-plugin-iso-import

Package Overview
Dependencies
Maintainers
0
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-iso-import

Import modules isomorphically

1.3.0
latest
Source
npmnpm
Version published
Weekly downloads
3.3K
6.86%
Maintainers
0
Weekly downloads
 
Created
Source

vite-plugin-iso-import

Import modules isomorphically. Vite discussion for potential built-in support.

Usage

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'

Installation

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()]
})

FAQ

What happens if I use an import value that has been stripped off?

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.

Using ?client and ?server loses intellisense

The 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'

License

MIT

Keywords

vite

FAQs

Package last updated on 04 Aug 2025

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.