Font-Awesome icon indicating copy to clipboard operation
Font-Awesome copied to clipboard

package doesn't appear to be written in CJS, but also doesn't appear to be a valid ES module (i.e. it doesn't have "type": "module" or an .mjs extension for the entry point). Please contact the package author to fix.

Open cor opened this issue 3 years ago • 12 comments

Describe the bug @fortawesome/fontawesome-free doesn't appear to be written in CJS, but also doesn't appear to be a valid ES module (i.e. it doesn't have "type": "module" or an .mjs extension for the entry point). Please contact the package author to fix. I'm using FontAwesome in my sveltekit app, and using vite v2.7.3. There I get this error message

To Reproduce

  1. Create a new sveltekit project:
npm init svelte@next my-app
cd my-app
npm install
  1. add @fortawesome/fontawesome-free as a dependency
  2. run npm run build

Expected behavior The error should not show up and it should be a valid es module

Version and implementation Version: "@fortawesome/fontawesome-free": "^5.15.4", "@sveltejs/kit": "1.0.0-next.202" vite v2.7.3

  • [x] SVG with JS
  • [ ] Web Fonts with CSS
  • [ ] SVG Sprites
  • [ ] On the Desktop

Bug report checklist

  • [x] I have filled out as much of the above information as I can
  • [x] I have included a test case because my odds go way up that the team can fix this when I do
  • [x] I have searched for existing issues and to the best of my knowledge this is not a duplicate

cor avatar Dec 16 '21 14:12 cor

same here.

AqueleHaru avatar Jan 10 '22 14:01 AqueleHaru

this is when using vitejs

nurdism avatar Jan 23 '22 07:01 nurdism

I had the same problem after installing it on a fresh svelte-kit/electron template (https://github.com/Dax89/electron-sveltekit).

OutlierSeeker avatar Jan 26 '22 14:01 OutlierSeeker

I have multiple projects getting this same warning.

iandoesallthethings avatar Feb 05 '22 04:02 iandoesallthethings

Me too. I also have problems with the icon method.

import { icon } from "@fortawesome/fontawesome-svg-core";
         ^^^^
SyntaxError: Named export 'icon' not found. The requested module '@fortawesome/fontawesome-svg-core' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from '@fortawesome/fontawesome-svg-core';
const { icon } = pkg;

I put it in an isolated repo here: https://github.com/fabianmossberg/fontawesome-problem

fabianmossberg avatar Mar 18 '22 18:03 fabianmossberg

A workaround until the packages are shipped as esm is to fix it in the vite config.

In SvelteKit, edit svelte.config.js and add '@fortawesome/*' to kit.vite.ssr.noExternal

https://github.com/fabianmossberg/fontawesome-problem/blob/7357af392e3858b726520a95688bb2a82d9913e0/svelte.config.js#L4-L13

fabianmossberg avatar Mar 19 '22 19:03 fabianmossberg

@fabianmossberg Glad you got it working; I made #18720 a month ago and it hasn’t been triaged, so I’m not expecting a prompt fix.

dbaynard avatar Mar 19 '22 20:03 dbaynard

@fabianmossberg Glad you got it working; I made #18720 a month ago and it hasn’t been triaged, so I’m not expecting a prompt fix.

I would guess that the files in the js-packages folder are coming from some private repos that the FontAwesome team are handling, so the fix needs to be done in their repos, not in this one.

fabianmossberg avatar Mar 19 '22 20:03 fabianmossberg

A workaround until the packages are shipped as esm is to fix it in the vite config.

In SvelteKit, edit svelte.config.js and add '@fortawesome/*' to kit.vite.ssr.noExternal

https://github.com/fabianmossberg/fontawesome-problem/blob/7357af392e3858b726520a95688bb2a82d9913e0/svelte.config.js#L4-L13

Same in vite with vue. It seems that ssr/ssg is the problem. The font awesome packages gets detected as commonjs modules. From the fontawesome project you can try to adjust the esm exports to be compatible with vite's automatic detection. Or maybe vite will improve its autodetection in the future. Meanwhile @fabianmossberg's answer also works for vite with vue:

// vite.config.ts
export default defineViteConfig({
  // ...
  ssr: {
    noExternal: ['@fortawesome/*'],
  },
});

cimchd avatar Mar 20 '22 13:03 cimchd

I'd argue this is a duplicate of #16439, right?

GuilleDF avatar Mar 25 '22 10:03 GuilleDF

See also https://github.com/FortAwesome/Font-Awesome/issues/18075, https://github.com/FortAwesome/Font-Awesome/issues/18677

rdela avatar May 04 '22 12:05 rdela

It appears the vite configuration no longer has the ssr: noExternal option. This is using vite 2.9.14. I see this comment in the index.d.ts file:

/* Excluded from this release type: ssr */

Jabronironi avatar Jul 13 '22 17:07 Jabronironi

I tried using the "All The Things" installation method and imported the js using the esm import syntax (import '@fortawesome/fontawesome-pro/js/solid.js';) and I still get that error on 6.2.0 using sveltekit. Am I importing the .js correctly?

The error: @fortawesome/fontawesome-pro doesn't appear to be written in CJS, but also doesn't appear to be a valid ES module (i.e. it doesn't have "type": "module" or an .mjs extension for the entry point). Please contact the package author to fix.

Using the "Certain Specific Things" installation works as expected.

cascading-jox avatar Sep 08 '22 11:09 cascading-jox

Am I importing the .js correctly?

I may be wrong, but using svelte and other JS frameworks with the Font Awesome JS+SVG implementation should require a different approach

There is a quite new svelte component that should be used for this use case. You may find more information at https://github.com/FortAwesome/svelte-fontawesome and examples

tagliala avatar Sep 08 '22 11:09 tagliala

think you can import normally (no workaround needed) now since #19041 https://github.com/FortAwesome/Font-Awesome/pull/19041#issuecomment-1232025150

rdela avatar Sep 08 '22 19:09 rdela

As of FA 6.2.0 and Vite, I still have the warning.

harryqt avatar Sep 18 '22 11:09 harryqt

I am also on 6.2.0 and seeing the same warning. Please reopen this issue

schlichtanders avatar Sep 29 '22 06:09 schlichtanders

Any chance to provide a reproducible test case?

Please provide as many information as possible (version of FA, how it is imported, version of Vite). Even better if it is possible to provide a reduced test case hosted on github

tagliala avatar Sep 29 '22 07:09 tagliala

@tagliala you can clone this repo Dibbyo456/fa-bug-report to reproduce.

harryqt avatar Oct 09 '22 09:10 harryqt