s-panferov / awesome-typescript-loader

Awesome TypeScript loader for webpack
Other
2.35k stars 179 forks source link

useBabel broken with Yarn Workspaces #499

Open khell opened 7 years ago

khell commented 7 years ago

If useBabel: true property is set under a Yarn Workspaces monorepo, and if babel-core has successfully been hoisted to the root node_modules directory, then at-loader fails and prints the error message BABEL_ERROR, because it can no longer find Babel at the absolute path specified by at-loader.

This can easily be resolved by also passing babelCore: 'babel-core', which then falls back onto Node's module resolution.

What is the reasoning behind not using Node's module resolution by default?

mattdsteele commented 7 years ago

This also breaks with a Lerna monorepo when using --hoist.

From their docs:

Unfortunately, some tooling does not follow the module resolution spec closely, and instead assumes or requires that dependencies are present specificially in the local node_modules directory. To work around this, it is possible to symlink packages from their hoisted top-level location, to individial package node_modules directory. Lerna does not yet do this automatically, and it is recommended instead to work with tool maintainers to migrate to more compatible patterns.

My workaround is to just make a symlink (or copy) babel-core into the package's node_modules.