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

Rollup warnings during UMD builds: "but could not be resolved -- treating it as an external dependency" and "No name was provided for external module" #989

Closed
zerofront opened this issue Mar 10, 2021 · 3 comments
Labels
kind: question This is a usage or similar question kind: support Asking for support with something or a specific use case problem: removed issue template OP removed the issue template without good cause problem: stale Issue has not been responded to in some time scope: upstream Issue in upstream dependency

Comments

@zerofront
Copy link

zerofront commented Mar 10, 2021

Current Behavior

I create a project webttttt by using tsdx create webttttt (select basic).

and create on simple function and build and publish in npm.

then I create another project by using tsdx create (select basic).

I import a function from webttttt and build package by using tsdx build --format cjs,esm,umd

then

⠸ Building modules  99%                 3.2s, estimated 3.2s
'webttttt' is imported by src/index.ts, but could not be resolved – treating it as an external dependency
'webttttt' is imported by src/index.ts, but could not be resolved – treating it as an external dependency
No name was provided for external module 'webttttt' in output.globals – guessing 'webttttt'
@agilgur5 agilgur5 added problem: removed issue template OP removed the issue template without good cause kind: question This is a usage or similar question kind: support Asking for support with something or a specific use case labels Mar 10, 2021
@agilgur5 agilgur5 changed the title but could not be resolved treating it as an external dependency Rollup warnings during UMD builds: "but could not be resolved -- treating it as an external dependency" and "No name was provided for external module" Mar 10, 2021
@agilgur5
Copy link
Collaborator

agilgur5 commented Mar 10, 2021

UMD context missing

So you removed the bottom half of the issue template -- please don't do that, it is there for a reason. Since you didn't fill it out, it's difficult to tell the context here, such as why you're building UMD specifically, how you plan on using UMD, and if you know what UMD entails. UMD is not part of TSDX's defaults and is not very popular in and out of TSDX (at least not in today's day and age of package managers). I'll try answering without that, but issue templates are important to fill out and giving context and intent is important when creating an issue.

How UMD in Rollup works

These are warnings from Rollup (and some core plugins) specifically for the UMD build. It seems like you may not be familiar with what UMD entails, so I'll summarize a bit below.

TSDX by default treats all absolute imports as externals, meaning that dependencies are not bundled.
For packages that are installed, that's fine and is in fact the norm, as the deps will automatically be brought in via a package manager like NPM.
In UMD though, that means the deps must exist in a global already. output.globals is where you specify the name of the global variable. If it's not explicitly specified, Rollup will "guess" as it did here.

Fixing globals warnings

That guess probably looks correct in your case, so you could ignore the warning, or to remove the warning, you could explocitly specify Rollup's output.globals via tsdx.config.js. That is partially discussed in #132.

If you'd prefer to bundle your deps in UMD, you can do so by following the directions in #179 (comment) .

Fixing "could not be resolved" warnings

Regarding the "could not be resolved" error, I can't seem to find what I thought was a @rollup/plugin-commonjs bug...

But that might be occurring correctly actually -- did you yarn install webttttt? It has to be in node_modules for @rollup/plugin-node-resolve to automatically pick it up.

@zerofront
Copy link
Author

zerofront commented Mar 11, 2021

@agilgur5

UMD context

I want to bundle deps in UMD to check the final size

Flow

project A

tsdx create A (select basic)`

change src/index.ts

import dayjs from 'dayjs'
import axios from 'axios'

const sum = (a: number, b: number) => {
  console.log('boop');
  return a + b;
};

const minus = (a: number, b: number) => {
  console.log('poop');
  return a - b;
};

export {
  sum,
  minus,
  dayjs,
  axios,
}

npm publish

project B

tsdx create B (select basic)`

change src/index.ts

import { minus } from 'A'

function final(a: number, b: number) {
  return minus(a, b)
}

export {
  final
}

change tsdx.config.js

module.exports = {
  rollup(config) {
    if (config.output.format === 'umd') {
      delete config.external;
    }
    return config;
  }
}

check umd.development.js and umd.production.min.js.
Both of these include dayjs and axios, although B does not use axios and dayjs

@agilgur5
Copy link
Collaborator

agilgur5 commented Mar 16, 2021

But that might be occurring correctly actually -- did you yarn install webttttt? It has to be in node_modules for @rollup/plugin-node-resolve to automatically pick it up.

This was never answered.

I want to bundle deps in UMD to check the final size

All TSDX templates come with size-limit for checking bundle size thanks to #705 , per the templates' READMEs (see yarn size and yarn analyze), so you wouldn't need UMD for that.

check umd.development.js and umd.production.min.js.
Both of these include dayjs and axios, although B does not use axios and dayjs

This was a tree-shaking question (I did not catch that on my initial read of this), and it was responded to separately in #992 which duplicated most of this comment.

@agilgur5 agilgur5 added the problem: stale Issue has not been responded to in some time label Apr 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: question This is a usage or similar question kind: support Asking for support with something or a specific use case problem: removed issue template OP removed the issue template without good cause problem: stale Issue has not been responded to in some time scope: upstream Issue in upstream dependency
Projects
None yet
Development

No branches or pull requests

2 participants