jaredpalmer / tsdx

Zero-config CLI for TypeScript package development
https://tsdx.io
MIT License
11.25k stars 508 forks source link

Build fails on 0.10.5: Cannot find module @babel/... #274

Closed Flydiverny closed 4 years ago

Flydiverny commented 4 years ago

Current Behavior

$ tsdx build
Error: Cannot find module '@babel/plugin-transform-runtime' from '/path-to-pkgs/packages/auth'

    at Function.module.exports [as sync] (/path-to-pkgs/packages/auth/node_modules/resolve/lib/sync.js:74:15)
    at resolveStandardizedName (/path-to-pkgs/packages/auth/node_modules/@wessberg/rollup-plugin-ts/node_modules/@babel/core/lib/config/files/plugins.js:101:31)
    at resolvePlugin (/path-to-pkgs/packages/auth/node_modules/@wessberg/rollup-plugin-ts/node_modules/@babel/core/lib/config/files/plugins.js:54:10)
    at loadPlugin (/path-to-pkgs/packages/auth/node_modules/@wessberg/rollup-plugin-ts/node_modules/@babel/core/lib/config/files/plugins.js:62:20)
    at createDescriptor (/path-to-pkgs/packages/auth/node_modules/@wessberg/rollup-plugin-ts/node_modules/@babel/core/lib/config/config-descriptors.js:154:9)
    at /path-to-pkgs/packages/auth/node_modules/@wessberg/rollup-plugin-ts/node_modules/@babel/core/lib/config/config-descriptors.js:109:50
    at Array.map (<anonymous>)
    at createDescriptors (/path-to-pkgs/packages/auth/node_modules/@wessberg/rollup-plugin-ts/node_modules/@babel/core/lib/config/config-descriptors.js:109:29)
    at createPluginDescriptors (/path-to-pkgs/packages/auth/node_modules/@wessberg/rollup-plugin-ts/node_modules/@babel/core/lib/config/config-descriptors.js:105:10)
    at /path-to-pkgs/packages/auth/node_modules/@wessberg/rollup-plugin-ts/node_modules/@babel/core/lib/config/config-descriptors.js:63:49

error Command failed with exit code 1.

Expected behavior

Build working like in 0.9.3 😄

Suggested solution(s)

Additional context

Build works fine in 0.9.3 but upgrading tsdx to latest breaks, doing yarn add @babel/plugin-transform-runtime leads to the same error with another babel plugin (@babel/plugin-syntax-dynamic-import)

Guessing this issue is related: https://github.com/wessberg/rollup-plugin-ts/issues/37

Your environment

Software Version(s)
TSDX 0.10.5
TypeScript 3.6.4
Browser N/A
npm/Yarn yarn 1.19.1
Node node v12.10.0
Operating System osx
jaredpalmer commented 4 years ago

@wessberg? Thoughts?

jaredpalmer commented 4 years ago

I am feeling like we should maybe revert back to rollup-plugin-typescript2

wessberg commented 4 years ago

@babel/plugin-transform-runtime is listed as a dependency here. rollup-plugin-ts has a deep babel integration, just like tsdx, so version conflicts between babel dependencies of the two packages may arise. In fact, all of the babel dependencies of tsdx are dependencies of rollup-plugin-ts and are applied in conjunction with the users babel config when babel is being used as the transpiler (as it is here, per your configuration).

@jaredpalmer, yeah, I understand why you feel that way. rollup-plugin-typescript2 is definitely much narrower scoped (no babel integration, no declaration bundling, etc), it's more of a simple wrapper around the TypeScript compiler API, which you may prefer for tsdx. The declaration bundling part of rollup-plugin-ts still have a few issues left to iron out, but we're getting there.

sadsa commented 4 years ago

@jaredpalmer - This issue also occurs for @babel/preset-env.

Error: Cannot find module '@babel/preset-env' from 'C:\Users\Josh\Projects\rush-example\libraries\my-controls'

Seems that these dependencies are being correctly installed, however as @wessberg mentions, there may be a conflict happening here when the module is being resolved. I'm using PNPM which might be a better tool for testing dependencies are installed reliably.

medelman17 commented 4 years ago

@wessberg -- what would you suggest we do, here? Curious if you see a path forward.

I think I can speak for folks and say, 'don't hold any punches,' right?

wessberg commented 4 years ago

@medelman17, well, I guess that comes down to whether or not you will proceed with rollup-plugin-ts or not. If you are, then the two packages may have conflicting babel dependencies from time to time. One solution could be to make rollup-plugin-ts fully responsible for all things related to Babel.

medelman17 commented 4 years ago

@wessberg -- Could you walk us through that? Pros / cons from your perspective?

wessberg commented 4 years ago

@medelman17 I've written a lot of details in the README, particularly the FAQ, that you may find relevant here.

But basically, as far as I can tell from the source code, you're running Babel twice. Tsdx uses babel through rollup-plugin-ts since you give it the transpiler: "babel" option and through babelPluginTsdx, another Rollup plugin.

I don't know if that plugin is doing anything special, but if not, you might as well leave it out, given that rollup-plugin-ts is very batteries-included when it comes to Babel.

Now, you may be doing something special with that plugin that I don't know, so it may not be as simple as that. I'm not intimate with the codebase of tsdx 🙂.

But in any case, there's a lot of overlap in the value proposition of tsdx and rollup-plugin-ts in relation to juggling the relationship between Babel, Browserslists, and Typescript, which will lead to dependency errors at some point as long as both packages need to sync their Babel dependencies. Moving all babel-related dependencies to peerDependencies might be an option, but I'm hesitant to do that since that's a lot of packages to ask the user to npm install (or whatever package manager you use, yarn, PNPM, what-have-you)

swyxio commented 4 years ago

we've rolled back the plugin change - open new issues for anything v0.11 and up