vite-plugin-node-polyfills icon indicating copy to clipboard operation
vite-plugin-node-polyfills copied to clipboard

Failed to resolve module specifier "vite-plugin-node-polyfills/shims/global". Relative references must start with either "/", "./", or "../".

Open jsoneaday opened this issue 1 year ago • 6 comments
trafficstars

Hello I've created an npm package using your package and I am able to build successfully. However when it runs on browser I see the error given. I suspect there is an issue in my vite.config.ts file but not sure what it is. Here's my file

`import { defineConfig } from "vite"; import wasm from "vite-plugin-wasm"; import { nodePolyfills } from "vite-plugin-node-polyfills"; import path from "path";

export default defineConfig({ resolve: { alias: { process: "process/browser", path: "path-browserify", stream: "stream-browserify", os: "os-browserify", }, }, plugins: [ wasm(), nodePolyfills({ // To exclude specific polyfills, add them to this list. exclude: [ "fs", // Excludes the polyfill for fs and node:fs. //"stream", ], // Whether to polyfill specific globals. globals: { Buffer: true, global: true, process: true, }, // Whether to polyfill node: protocol imports. protocolImports: true, }), ], build: { manifest: true, minify: true, reportCompressedSize: true, lib: { entry: path.resolve(__dirname, "src/main.ts"), fileName: "main", formats: ["es", "cjs"], }, target: "esnext", rollupOptions: { external: [ "vite-plugin-node-polyfills/shims/buffer", "vite-plugin-node-polyfills/shims/global", "vite-plugin-node-polyfills/shims/process", ], }, }, }); `

jsoneaday avatar Feb 08 '24 14:02 jsoneaday

have the same issue for my linked package image

andriirak avatar Feb 09 '24 08:02 andriirak

@jsoneaday it looks like you are externalizing the shims for buffer, global, and process. Without a full reproduction, I can't diagnose the problem or provide a fix.

davidmyersdev avatar Feb 09 '24 23:02 davidmyersdev

have the same issue for my linked package image

Adding vite-plugin-node-polyfills as dependency to the linked package somehow worked, but it is not ideal. I suspect it is because of the linking and rollup is looking for the package in the wrong context? 🤯

bompi88 avatar Apr 10 '24 12:04 bompi88

I came across this today and was able to resolve it by telling the plugin NOT to polyfill process:

nodePolyfills({
  globals: {
    // Don't polyfill these globals
    process: false,
    Buffer: false,
  },
}),

JordanBerger avatar Jul 03 '24 22:07 JordanBerger

Downgrading this plugin to 0.17.0 fixed this error for me.

wesbiggs avatar Aug 23 '24 14:08 wesbiggs

Downgrading this plugin to 0.17.0 fixed this error for me.

Have the same issue, downgrading solve the problem as well... Let me know if you can help with this issue

chitter99 avatar Oct 03 '24 20:10 chitter99

I'm closing this for now. If a reproduction of the issue is provided, I'll reopen it.

davidmyersdev avatar Oct 17 '24 03:10 davidmyersdev