iam-medvedev / esbuild-plugin-less

esbuild plugin for less files
https://npmjs.com/package/esbuild-plugin-less
Do What The F*ck You Want To Public License
43 stars 12 forks source link

Cannot be used as an ES module #7

Closed philipahlberg closed 3 years ago

philipahlberg commented 3 years ago

Attempting to use the package as an ES module yields the following error:

import { lessLoader } from 'esbuild-plugin-less';
         ^^^^^^^^^^
SyntaxError: Named export 'lessLoader' not found. The requested module 'esbuild-plugin-less' 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 'esbuild-plugin-less';
const { lessLoader } = pkg;

    at ModuleJob._instantiate (internal/modules/esm/module_job.js:104:21)
    at async ModuleJob.run (internal/modules/esm/module_job.js:149:5)
    at async Loader.import (internal/modules/esm/loader.js:166:24)
    at async Object.loadESM (internal/process/esm_loader.js:68:5)
error Command failed with exit code 1.

Applying the suggestion to use it as a CJS module yields another error:

import pkg from 'esbuild-plugin-less';
       ^^^
SyntaxError: The requested module 'esbuild-plugin-less' does not provide an export named 'default'
    at ModuleJob._instantiate (internal/modules/esm/module_job.js:104:21)
    at async ModuleJob.run (internal/modules/esm/module_job.js:149:5)
    at async Loader.import (internal/modules/esm/loader.js:166:24)
    at async Object.loadESM (internal/process/esm_loader.js:68:5)
error Command failed with exit code 1.

However, changing the exports.import field in package.json (and renaming the corresponding file) fixes the issue:

  "exports": {
    "import": "./build/esm.mjs",
    "require": "./build/cjs.js"
  },

This is on Node.js v14.15.4.

github-actions[bot] commented 3 years ago

:tada: This issue has been resolved in version 1.0.2 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

iam-medvedev commented 3 years ago

@philipahlberg I fixed this in version 1.0.2 Can you confirm if this fix works?

philipahlberg commented 3 years ago

It works! Thank you for the quick response and release. :+1: