samhaeng / naevner

Javascript plugin that provides natural language descriptions of hex color codes. By https://samhaeng.com/

Home Page:https://naevner.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Default export not working in production env

kyrregjerstad opened this issue · comments

Description:
I have been experiencing difficulties while trying to import the naevner function from your TypeScript module. I believe there might be an issue with the way the function is exported.

Steps to Reproduce:

  1. Import the naevner function into another TypeScript/JavaScript file using import naevner from "@samhaeng/naevner.;
  2. The function works as expected in the dev env
  3. Build the app with Vite
  4. Open the build preview
  5. Observe the error in the console:

TypeError: naevner is not a function

Expected Behavior:
The naevner function should be successfully imported and usable in the build without throwing any errors.

Actual Behavior:
Currently, an error is thrown.

Workaround:
The current workaround I am using is to add the .default to the export as follows:

// node_modules/.pnpm/@samhaeng+naevner@1.0.5/node_modules/@samhaeng/naevner/dist/index.js
'use strict'

if (process.env.NODE_ENV === 'production') {
  module.exports = require('./naevner.cjs.production.min.js').default
} else {
  module.exports = require('./naevner.cjs.development.js').default
}

Additional Information:

  • TypeScript version: 5.0.4
  • Node.js version: 18.16.0
  • Build tool: Vite 4.3.0

Thanks for creating such a neat little tool!