nix-community / yarn2nix

Generate nix expressions from a yarn.lock file [maintainer=???]
GNU General Public License v3.0
123 stars 61 forks source link

Shared babel.config.js in yarn workspaces #105

Open uvNikita opened 5 years ago

uvNikita commented 5 years ago

This issue is about the same project which is described here #104, but since it's somewhat independent, I thought it will be better to create a separate issue.

As you can see in the described project structure, we have a babel.config.js shared between different workspaces, but when I try to run webpack as part of the build process, it can't find this file. The rootMode is set to "upward": https://babeljs.io/docs/en/options#rootmode. Here is frontend/default.nix file that I've tried so far:

{ yarn2nix, git }:

let
  workspaces = yarn2nix.mkYarnWorkspace {
    name = "workspaces";
    src = ./.;
    shellHook = yarn2nix.linkNodeModulesHook;
    packageOverrides = {
      w1 = {
        extraBuildInputs = [ git ];
        distPhase = ''
          cd $out/libexec/@company/w1/deps/@company/w1
          mkdir -p $out/dist/static
          export NODE_ENV=production
          export BABEL_CACHE_PATH=$TMPDIR/.babelcache.json
          # yarn build == webpack
          yarn build --progress false --output-path $out/dist/static
        '';
      };
    };

  };

in

workspaces.w1

Here is partial log output from nix-build:

 webpack --progress --progress false --output-path /nix/store/af4f3kf920jsrvzcvfh61fd4drbsqldv-workspaces/dist/static
warning Cannot find a suitable global folder. Tried these: "/usr/local, /homeless-shelter/.yarn"
[webpack] Webpack using NODE_ENV="production"

Hash: 3c959d08cfb1983b7ed8
Version: webpack 4.32.2
Time: 318ms
Built at: 2019-06-04 08:18:48
 1 asset
Entrypoint w1-app = w1-app-3c959d08cfb1983b7ed8.js
[0] ./src/main.jsx 2.05 KiB {0} [built] [failed] [1 error]

ERROR in ./src/main.jsx
Module build failed (from /nix/store/af4f3kf920jsrvzcvfh61fd4drbsqldv-workspaces/libexec/@company/w1/node_modules/babel-loader/lib/index.js):
Error: Babel was run with rootMode:"upward" but a root could not be found when searching upward from "/nix/store/af4f3kf920jsrvzcvfh61fd4drbsqldv-workspaces/libexec/@company/w1/deps/@company/w1"
    at resolveRootMode (/nix/store/af4f3kf920jsrvzcvfh61fd4drbsqldv-workspaces/libexec/@company/w1/node_modules/@babel/core/lib/config/partial.js:50:29)
    at loadPrivatePartialConfig (/nix/store/af4f3kf920jsrvzcvfh61fd4drbsqldv-workspaces/libexec/@company/w1/node_modules/@babel/core/lib/config/partial.js:77:27)
    at Object.loadPartialConfig (/nix/store/af4f3kf920jsrvzcvfh61fd4drbsqldv-workspaces/libexec/@company/w1/node_modules/@babel/core/lib/config/partial.js:110:18)
    at Object.<anonymous> (/nix/store/af4f3kf920jsrvzcvfh61fd4drbsqldv-workspaces/libexec/@company/w1/node_modules/babel-loader/lib/index.js:144:26)
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/nix/store/af4f3kf920jsrvzcvfh61fd4drbsqldv-workspaces/libexec/@company/w1/node_modules/babel-loader/lib/index.js:3:103)
    at _next (/nix/store/af4f3kf920jsrvzcvfh61fd4drbsqldv-workspaces/libexec/@company/w1/node_modules/babel-loader/lib/index.js:5:194)
    at /nix/store/af4f3kf920jsrvzcvfh61fd4drbsqldv-workspaces/libexec/@company/w1/node_modules/babel-loader/lib/index.js:5:364
    at new Promise (<anonymous>)
    at Object.<anonymous> (/nix/store/af4f3kf920jsrvzcvfh61fd4drbsqldv-workspaces/libexec/@company/w1/node_modules/babel-loader/lib/index.js:5:97)
    at Object._loader (/nix/store/af4f3kf920jsrvzcvfh61fd4drbsqldv-workspaces/libexec/@company/w1/node_modules/babel-loader/lib/index.js:224:18)
    at Object.loader (/nix/store/af4f3kf920jsrvzcvfh61fd4drbsqldv-workspaces/libexec/@company/w1/node_modules/babel-loader/lib/index.js:60:18)
    at Object.<anonymous> (/nix/store/af4f3kf920jsrvzcvfh61fd4drbsqldv-workspaces/libexec/@company/w1/node_modules/babel-loader/lib/index.js:55:12)
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
builder for '/nix/store/mmizgm8jhc51lgfwcpwdvrc82pqfilch-workspaces.drv' failed with exit code 1
cannot build derivation '/nix/store/hkwh3ndvmkg7584zb5zrhjgmqa1abmin-w1-root.drv': 1 dependencies couldn't be built

Another similar issue we have is that we are using git-revision-webpack-plugin which generates version based on git revision, but since our .git is located in the parent folder (root of the project and not in frontend subfoler), it can't find it in the source folder copied to nix store.

Maybe you have some advice on how we can solve this?