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

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

Open
jsoneaday opened this issue Feb 8, 2024 · 5 comments
Labels
missing reproduction This issue does not provide a reproducible example of the problem.

Comments

@jsoneaday
Copy link

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",
],
},
},
});
`

@andriirak
Copy link

have the same issue for my linked package
image

@davidmyersdev
Copy link
Owner

@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 davidmyersdev added the missing reproduction This issue does not provide a reproducible example of the problem. label Feb 9, 2024
@bompi88
Copy link

bompi88 commented Apr 10, 2024

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

@JordanBerger
Copy link

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,
  },
}),

@wesbiggs
Copy link

Downgrading this plugin to 0.17.0 fixed this error for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
missing reproduction This issue does not provide a reproducible example of the problem.
Projects
None yet
Development

No branches or pull requests

6 participants