Is it possible for Yarn to fail to include both ESM and CJS versions of a package during publishing or adding?

Our application is equipped with Parcel and utilizes a UI library consisting of react components. This UI library is built with Rollup and is privately published on NPM.

I've been attempting to transition our application to Parcel 2, but I'm facing an issue where Parcel is unable to locate the ESM version of the UI library in the dist folder. Upon inspection of the node_modules directory, I discovered that the dist folder of the UI library contains only one file: index.cjs.js.

What's perplexing is that the UI library is configured to generate both CJS and ESM formats along with sourcemaps. When I compile the project locally, Rollup generates both CJS and ESM files along with their respective sourcemaps: index.cjs.js, index.cjs.js.map, index.esm.js, and index.esm.js.map. It appears that either: (1) Yarn is publishing only the CJS version to NPM or (2) When the UI library is added to the application, only the CJS version is being built. Neither of these scenarios seem logical to me.

Below are excerpts from our package.json and rollup.config.js files:

{
    "name": "@thecb/components",
    "version": "4.0.23",
    "description": "Common lib for CityBase react components",
    "main": "dist/index.cjs.js",
    "module": "dist/index.esm.js",
    "source": "src/index.js",
    "scripts": {
        "storybook": "start-storybook",
        "build": "rollup -cm"
    },
import resolve from "rollup-plugin-node-resolve";
import commonjs from "rollup-plugin-commonjs";
import babel from "rollup-plugin-babel";
import json from "rollup-plugin-json";
import visualizer from "rollup-plugin-visualizer";
import pkg from "./package.json";

import * as formattedInput from "formatted-input";

const globals = {
    react: "React",
    "react-dom": "ReactDOM"
};

const plugins = [
    resolve({ preferBuiltins: false }),
    babel({
        exclude: "node_modules/**",
        presets: ["@babel/env", "@babel/preset-react"]
    }),
    json(),
    commonjs({
        include: "node_modules/**",
        namedExports: {
            "formatted-input": Object.keys(formattedInput)
        }
    }),
    visualizer()
];

const external = [...Object.keys(pkg.peerDependencies || {})];

const output_data = [
    {
        file: pkg.main,
        format: "cjs"
    },
    {
        file: pkg.module,
        format: "esm"
    }
];

export default output_data.map(({ file, format }) => ({
    input: "src/index.js",
    output: {
        file,
        format,
        globals
    },
    plugins,
    external
}));

Can anyone shed light on why the ESM version of this library might not be getting published or installed?

Answer №1

Sorry for the delay in response, I encountered a similar issue today. Instead of using rollup, I used tsc directly to generate dist/cjs/* and dist/esm/*.

Interestingly, while my local build process generated both outputs, the package tarball created by yarn publish only included dist/cjs/*. My current theory is that yarn may be relying on the

"main": "dist/cjs/index.js"
configuration to determine the default package inclusions.

However, adding

"files": "dist"
to my package.json resolved the issue and prompted yarn to include both dist/cjs/* and dist/esm/* in the package tarball as expected.

https://docs.npmjs.com/cli/v7/configuring-npm/package-json#files

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The CSS class names for Next.js have not been defined yet

Just getting started with next js and trying to use css modules for styling my nav component. However, I noticed that the classname I setup for the nav element is not showing up in the rendered DOM. Even though I can see the generated styles by webpack in ...

Unable to conceal the innerHTML once the error has been rectified

My error messages are displayed using innerHTML. How can I make them disappear once the error is corrected? Currently, they stay on, even after the error is fixed. I tried resetting them at the top of the script but it didn't work. Link to JSfiddle ...

The power of Karma, AngularJS, Bootstrap, and the window variable working

As I work on testing my application, I am facing an issue with loading files using Karma into PhantomJS. The problem arises when one of the files triggers a page reload due to window variables. The files are being included in this manner: files: [ &a ...

Having trouble connecting to the webserver? Make sure the web server is up and running, and that incoming HTTP requests are not being blocked by a firewall

While working on my Visual Studio 2013 Asp.Net web code using the Local IIS Web server Version 7 (Windows 7 x64) and Framework 4.0, I encountered an error message stating: "Unable to start debugging on the web server. Unable to connect to the webserver. V ...

Transferring a JavaScript variable to a PHP file through jQuery's Ajax functionality

I'm having trouble figuring out how to pass a JavaScript variable to a PHP script using AJAX. This is my first attempt at using AJAX and I seem to be missing something. Here's the code snippet: function selectCategory(value) { $.ajax({ ...

What is the best way to export assets into a React Native JS file?

After watching a video on YouTube, I noticed that at 3:20 the individual in the video quickly exported multiple assets into a file without providing any explanation. Can someone please view this specific moment in the video and clarify how this person mana ...

Experiencing issues with npm installation and Git usage following the upgrade to MacOS Mojave 10.14.4 (18E226)?

Initially, the system works fine after a restart. However, I repeatedly encounter the following error: curl: (35) LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to ssl.icu-project.org:443 and request failed ... read ECONNRESET This issue arises c ...

Issue with executing a jQuery event within a JavaScript object due to application error

I am struggling to comprehend how to set listeners in my JavaScript object. For instance: var obj = function(){ this.test = function(){ console.log('test'); } $(document).on('click','#test',(function(){ ...

What methods can be used to defer the visibility of a block in HTML?

Is there a way to reveal a block of text (h4) after a delay once the page has finished loading? Would it be necessary to utilize setTimeout for this purpose? ...

Seeking assistance in the development of a visual depiction of device orientation through JS

My goal is to visually represent the device orientation values alpha, beta, and gamma by creating a series of "bars" for each value. Currently, I have managed to display only the values in plain text using innerHTML. However, I envision these bars moving i ...

PHP - Issue with AJAX Login Functionality

I have been developing an AJAX login system and encountering an issue where it does not send any response back unless I use exit("error here") in the script. However, my goal is to return a JSON response instead. The form structure: <div id="account" ...

Enhance the jQueryUI progress bar by dynamically updating it with inner HTML data

I am working on implementing a jQueryUI progress bar and facing some challenges. Here is the basic code for the progress bar: <script> $(function() { $("#progressbar").progressbar({ value: 50, }); }); </script& ...

Create a custom countdown using Jquery and Javascript that integrates with MySQL and PHP to display the datetime in the format Y-m-d

Hey there, I'm looking to create a countdown script using dates in the format (Y-m-d H:m:s). The goal is to retrieve the current_datetime and expire_datetime in this format and incorporate them into some JavaScript or jQuery plugin to display a countd ...

Enhance your <head> section by adding lines when utilizing Layouts within Iron Router

Is there a way to add more lines to the <head> section using Iron Router and layouts? Take for example, inserting the following code snippet into the <head>... <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=ed ...

Integrating tooltips on Dimple.js line charts

A simplified network-style chart has been created using Dimple's line plot as the foundation. For example, please refer to this link: http://jsfiddle.net/cc1gpt2o/ myChart.addCategoryAxis("x", "Entity"); myChart.addCategoryAxis("y", "Entity").add ...

Sharing state between two functions in React using Hooks

Coming from a background in Vue, I am struggling to comprehend how to conditionally show something when the HTML is fragmented into different parts. Imagine having this structure: import React, { useState } from "react"; const [mobileNavOpen, setMobi ...

Implement Google Apps Script Array in HTML form for autocompleting datalist suggestions

I have successfully created a Google Scripts function that generates an array from a column in a Google Sheet by filtering out any spaces. However, I'm facing a challenge in figuring out how to pass this variable to my HTML form so that I can set up a ...

How to properly Open a "div" Element by its ID in ReactJS

Today, I want to share an issue that I've been facing. To simplify things, I have mapped a BDD, The result of this mapping is displayed in multiple cards, There's a button that when clicked opens up more details on the map, But here's wh ...

Extracting a particular element from a sophisticated auto-complete DOM structure by drilling down into the $scope

After spending a significant amount of time trying to solve this problem, I find myself at a dead end. The simplicity of using jQuery makes me reconsider Angular, but perhaps my approach is flawed. In this scenario, the DOM structure looks like this: < ...

What is the best way to link a newly created contact to the current user in Mongoose?

I'm faced with the challenge of creating a contact that is specifically added to the current user's contact array. Currently, my controller only creates a generic contact and doesn't cater to the individual user. Controller: function cont ...