1

Context

Our product is (sadly) still on Webpack 3. Hope to upgrade, but in the meantime, I am trying to use an npm library that bundles cjs, mjs and iffe files. (See package.json excerpt below).

The problem is that Webpack complains when I import from these files.

import { styled } from '@stitches/react';

This throws the following error:

ERROR in ./node_modules/@stitches/react/dist/index.cjs
Module parse failed: Unexpected token (1:9356)
You may need an appropriate loader to handle this file type.

The unexpected token is something random like n or a variable name. The source code is used widely in the community so it's likely not a bug in the code.

Works when copy-pasting the code into src

In our Babel setup, we don't touch anything in node_modules, but when I copy the contents of dist/index.cjs or dist/index.mjs into our src directory and import it there, everything works fine.

This looks to me like the source code has issues with either a) how it's imported as a module, or b) it requires some kind of transpilation to work with our setup.

The question

Is this somehow related to Webpack 3? Are mjs and cjs files problematic?

package.json


{
  "name": "@stitches/react",
  "version": "0.2.3",
  "description": "The modern CSS-in-JS library",
  "type": "module",
  "main": "dist/index.cjs",
  "module": "dist/index.mjs",
  "types": "types/index.d.ts",
  "typesVersions": {
    ">= 4.1": {
      "*": [
        "types/index.d.ts"
      ]
    }
  },
  "jsdelivr": "dist/index.iife.js",
  "unpkg": "dist/index.iife.js",
  "exports": {
    ".": {
      "require": "./dist/index.cjs",
      "import": "./dist/index.mjs",
      "types": "./types/index.d.ts"
    }
  },
  • Why are you going through all this when you could invest the time in upgrading to a more recent webpack? – Evert Jul 29 '21 at 23:03
  • Good question! The answer is priorities. I agree we should upgrade and hopefully we can soon. This question is about whether or not there's a clear reason why this doesn't work and if it's webpack 3 related – Lucas Arundell Jul 30 '21 at 03:31

0 Answers0