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

Issues with global and other polyfills (especially with vite dev server) #14

Open
jmandel opened this issue Apr 7, 2021 · 0 comments
Open

Comments

@jmandel
Copy link

jmandel commented Apr 7, 2021

If I manually patch for #8, I still hit a number of issues that prevent this plugin from working with vite's dev server. I'm not sure where the underlying causes sit, so I'm outlining the issues here to start.

In the examples below, I'm working with a tiny test ("tt") module that contains just a single js file that references global.

import nodePolyfills from 'rollup-plugin-polyfill-node';

export default {
  plugins: [
  nodePolyfills({
    include: [
      '*.js',
      'node_modules/**/*.js', 
      // (1)
      new RegExp('node_modules/.vite/.*js')],
    // (2)
    exclude: ['node_modules/polyfill-nodeglobal.js']
  }),
]};

(1) In the dev server, requests come for files like "http://localhost:3000/node_modules/.vite/tt.js?v=75d8e834" -- and the ?v= parameter prevents the standard node_modules/**/*.js from matching these requests.

(2) There is no actual node_modules/polyfill-nodeglobal.js file on my disk, but without this exclude, I get a circular reference in the global polyfill. That is, "http://localhost:3000/@id/__x00__polyfill-node:global.js" has content like:

import { default as global } from '/@id/__x00__polyfill-node:global.js';

export default (typeof global !== "undefined" ? global :
  typeof self !== "undefined" ? self :
  typeof window !== "undefined" ? window : {});

(3) In the transformed content generated by this plugin, map.sources is populated with a value like sources: [ '../tt/index.js', 'dep:tt' ]. I'm not sure what the dep: array entry indicates, but the vite dev server crashes on this when it tries to find a filesystem entry named dep:tt.

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