Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning by using @mattermost/client in ESM #324

Open
Lyokolux opened this issue Jun 30, 2022 · 5 comments
Open

Warning by using @mattermost/client in ESM #324

Lyokolux opened this issue Jun 30, 2022 · 5 comments

Comments

@Lyokolux
Copy link

Though Mattermost is usable, I get the warning :

@mattermost/client 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.

A "type": "module" in the package.json is also used.

@Marthym
Copy link
Collaborator

Marthym commented Jun 30, 2022

Hi, thank for the warning, can you please give us more details on how to reproduce ?
The node version ?
...

@Lyokolux
Copy link
Author

Lyokolux commented Jun 30, 2022

Node version: 16.13.2

In my project, I use import { Client4 } from '@mattermost/client' with this warning only.

Reproduction can be found while using Nuxt 3: https://stackblitz.com/edit/nuxt-starter-m68mre?file=server/mattermost.ts
This one raises an error on Stackblitz:

import pkg from 'file:///home/projects/nuxt-starter-m68mre/node_modules/@mattermost/client/lib/index.js';
const { Client4 } = pkg;

import { Client4 } from 'node_modules/@mattermost/client/lib/index.js';
^^^^^^^
SyntaxError: Named export 'Client4' not found. The requested module 'node_modules/@mattermost/client/lib/index.js' 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 'node_modules/@mattermost/client/lib/index.js';
const { Client4 } = pkg;

As the error says

The requested module 'node_modules/@mattermost/client/lib/index.js' is a CommonJS module

But I have read that the @mattermost/client package is already written in ESM. After an npm install, I can fix it for myself by adding type: "module" in the node_modules/@mattermost/client/package.json. I don't know if it will break on other projects though. I suppose not, as the entire package is already written in ESM.

@Marthym
Copy link
Collaborator

Marthym commented Jul 1, 2022

Thanks for that, we will try to fix that asap.

@Marthym Marthym self-assigned this Jul 1, 2022
@Lyokolux
Copy link
Author

Any updates?

@Marthym
Copy link
Collaborator

Marthym commented Oct 26, 2022

Topic still in progress, we don't have much time to work on it

If you know how to fix it, feel free to propose a PR, I'll quickly review it and merge it

@Marthym Marthym removed their assignment Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants