FortAwesome/Font-Awesome

Bug: Global Variable Collision

eoussama opened this issue · 0 comments

Bug description

When using this package with vite.js, defining any key/value in vite's configuration can result in collisions that always result in build errors later on.

Take this configuration for example:

export default defineConfig({
  base: '/',
  plugins: [],
  define: {
    config: {
      version: '0.3.0'
    }
  }
})

There already exists a global variable named config used internally, for instance, in fontawesome-svg-core/index.mjs we have:

var library = new Library();
var noAuto = function noAuto() {
  config.autoReplaceSvg = false;
  config.observeMutations = false;
  callHooks('noAuto');
};

This will result in the following error during the build stage as vite overrides config's value:

Unexpected token (Note that you need plugins to import files that are not JavaScript)
file: /home/eoussama/projects/playback-sync/node_modules/@fortawesome/fontawesome-svg-core/index.mjs:1274:12
1272: var library = new Library();
1273: var noAuto = function noAuto() {
1274:   config.autoReplaceSvg = false;
                  ^
1275:   config.observeMutations = false;
1276:   callHooks('noAuto');
error during build:
RollupError: Unexpected token (Note that you need plugins to import files that are not JavaScript)
    at error (file:///home/eoussama/projects/playback-sync/node_modules/rollup/dist/es/shared/node-entry.js:2287:30)
    at Module.error (file:///home/eoussama/projects/playback-sync/node_modules/rollup/dist/es/shared/node-entry.js:13745:16)
    at Module.tryParse (file:///home/eoussama/projects/playback-sync/node_modules/rollup/dist/es/shared/node-entry.js:14476:25)
    at Module.setSource (file:///home/eoussama/projects/playback-sync/node_modules/rollup/dist/es/shared/node-entry.js:14077:39)
    at ModuleLoader.addModuleSource (file:///home/eoussama/projects/playback-sync/node_modules/rollup/dist/es/shared/node-entry.js:24649:20)
ERROR: "build-only" exited with 1.

Reproducible test case

No response

Screenshots

image

Font Awesome version

6.4.2

Serving

Kit

Implementation

SVG+JS

Browser and Operating System

Microsoft Edge
Version 119.0.2151.44 (Official build) (64-bit) on Windows 11

Web bug report checklist

  • I have included a test case because my odds go way up that the team can fix this when I do
  • I have searched for existing issues and to the best of my knowledge this is not a duplicate