Yarn Workspaces and Browserify - package.json in subfolder breaks the build












7















My ultimate goal is to use Yarn Workspaces in a project using Browserify and Babel 7. This is a minimal reproduction of a problem I'm having. Basically it seems that the presence of a package.json file in a subfolder (which is one of the things that you have when using Yarn Workspaces) breaks my Browserify build, and I can't figure out why.



Here's a GitHub repo with a minimal reproduction of the problem.



First, install the dependencies (you can use yarn or npm, doesn't matter):



$ npm install


Then confirm the Browserify+Babel build works:



$ npm run build

> browserify-babelify-yarn-workspaces@1.0.0 build /home/user/projects/browserify-babelify-yarn-workspaces
> browserify a/index.js -t babelify --outfile bundle.js


Yay, all is good! My compiled code is in bundle.js.



Now let's make a dummy package.json within the a folder:



$ echo "{}" > a/package.json


That shouldn't change the build, right? Wrong:



$ npm run build

> browserify-babelify-yarn-workspaces@1.0.0 build /home/user/projects/browserify-babelify-yarn-workspaces
> browserify a/index.js -t babelify --outfile bundle.js


/home/user/projects/browserify-babelify-yarn-workspaces/a/index.js:1
import lib from "./lib.js";
^
ParseError: 'import' and 'export' may appear only with 'sourceType: module'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! browserify-babelify-yarn-workspaces@1.0.0 build: `browserify a/index.js -t babelify --outfile bundle.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the browserify-babelify-yarn-workspaces@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /home/user/.npm/_logs/2018-11-16T15_58_43_540Z-debug.log


I can't figure out why this is happening. Any help would be appreciated!










share|improve this question





























    7















    My ultimate goal is to use Yarn Workspaces in a project using Browserify and Babel 7. This is a minimal reproduction of a problem I'm having. Basically it seems that the presence of a package.json file in a subfolder (which is one of the things that you have when using Yarn Workspaces) breaks my Browserify build, and I can't figure out why.



    Here's a GitHub repo with a minimal reproduction of the problem.



    First, install the dependencies (you can use yarn or npm, doesn't matter):



    $ npm install


    Then confirm the Browserify+Babel build works:



    $ npm run build

    > browserify-babelify-yarn-workspaces@1.0.0 build /home/user/projects/browserify-babelify-yarn-workspaces
    > browserify a/index.js -t babelify --outfile bundle.js


    Yay, all is good! My compiled code is in bundle.js.



    Now let's make a dummy package.json within the a folder:



    $ echo "{}" > a/package.json


    That shouldn't change the build, right? Wrong:



    $ npm run build

    > browserify-babelify-yarn-workspaces@1.0.0 build /home/user/projects/browserify-babelify-yarn-workspaces
    > browserify a/index.js -t babelify --outfile bundle.js


    /home/user/projects/browserify-babelify-yarn-workspaces/a/index.js:1
    import lib from "./lib.js";
    ^
    ParseError: 'import' and 'export' may appear only with 'sourceType: module'
    npm ERR! code ELIFECYCLE
    npm ERR! errno 1
    npm ERR! browserify-babelify-yarn-workspaces@1.0.0 build: `browserify a/index.js -t babelify --outfile bundle.js`
    npm ERR! Exit status 1
    npm ERR!
    npm ERR! Failed at the browserify-babelify-yarn-workspaces@1.0.0 build script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

    npm ERR! A complete log of this run can be found in:
    npm ERR! /home/user/.npm/_logs/2018-11-16T15_58_43_540Z-debug.log


    I can't figure out why this is happening. Any help would be appreciated!










    share|improve this question



























      7












      7








      7


      0






      My ultimate goal is to use Yarn Workspaces in a project using Browserify and Babel 7. This is a minimal reproduction of a problem I'm having. Basically it seems that the presence of a package.json file in a subfolder (which is one of the things that you have when using Yarn Workspaces) breaks my Browserify build, and I can't figure out why.



      Here's a GitHub repo with a minimal reproduction of the problem.



      First, install the dependencies (you can use yarn or npm, doesn't matter):



      $ npm install


      Then confirm the Browserify+Babel build works:



      $ npm run build

      > browserify-babelify-yarn-workspaces@1.0.0 build /home/user/projects/browserify-babelify-yarn-workspaces
      > browserify a/index.js -t babelify --outfile bundle.js


      Yay, all is good! My compiled code is in bundle.js.



      Now let's make a dummy package.json within the a folder:



      $ echo "{}" > a/package.json


      That shouldn't change the build, right? Wrong:



      $ npm run build

      > browserify-babelify-yarn-workspaces@1.0.0 build /home/user/projects/browserify-babelify-yarn-workspaces
      > browserify a/index.js -t babelify --outfile bundle.js


      /home/user/projects/browserify-babelify-yarn-workspaces/a/index.js:1
      import lib from "./lib.js";
      ^
      ParseError: 'import' and 'export' may appear only with 'sourceType: module'
      npm ERR! code ELIFECYCLE
      npm ERR! errno 1
      npm ERR! browserify-babelify-yarn-workspaces@1.0.0 build: `browserify a/index.js -t babelify --outfile bundle.js`
      npm ERR! Exit status 1
      npm ERR!
      npm ERR! Failed at the browserify-babelify-yarn-workspaces@1.0.0 build script.
      npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

      npm ERR! A complete log of this run can be found in:
      npm ERR! /home/user/.npm/_logs/2018-11-16T15_58_43_540Z-debug.log


      I can't figure out why this is happening. Any help would be appreciated!










      share|improve this question
















      My ultimate goal is to use Yarn Workspaces in a project using Browserify and Babel 7. This is a minimal reproduction of a problem I'm having. Basically it seems that the presence of a package.json file in a subfolder (which is one of the things that you have when using Yarn Workspaces) breaks my Browserify build, and I can't figure out why.



      Here's a GitHub repo with a minimal reproduction of the problem.



      First, install the dependencies (you can use yarn or npm, doesn't matter):



      $ npm install


      Then confirm the Browserify+Babel build works:



      $ npm run build

      > browserify-babelify-yarn-workspaces@1.0.0 build /home/user/projects/browserify-babelify-yarn-workspaces
      > browserify a/index.js -t babelify --outfile bundle.js


      Yay, all is good! My compiled code is in bundle.js.



      Now let's make a dummy package.json within the a folder:



      $ echo "{}" > a/package.json


      That shouldn't change the build, right? Wrong:



      $ npm run build

      > browserify-babelify-yarn-workspaces@1.0.0 build /home/user/projects/browserify-babelify-yarn-workspaces
      > browserify a/index.js -t babelify --outfile bundle.js


      /home/user/projects/browserify-babelify-yarn-workspaces/a/index.js:1
      import lib from "./lib.js";
      ^
      ParseError: 'import' and 'export' may appear only with 'sourceType: module'
      npm ERR! code ELIFECYCLE
      npm ERR! errno 1
      npm ERR! browserify-babelify-yarn-workspaces@1.0.0 build: `browserify a/index.js -t babelify --outfile bundle.js`
      npm ERR! Exit status 1
      npm ERR!
      npm ERR! Failed at the browserify-babelify-yarn-workspaces@1.0.0 build script.
      npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

      npm ERR! A complete log of this run can be found in:
      npm ERR! /home/user/.npm/_logs/2018-11-16T15_58_43_540Z-debug.log


      I can't figure out why this is happening. Any help would be appreciated!







      javascript browserify babel babelify yarn-workspaces






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 23 '18 at 15:16







      dumbmatter

















      asked Nov 16 '18 at 16:13









      dumbmatterdumbmatter

      5,13042561




      5,13042561
























          2 Answers
          2






          active

          oldest

          votes


















          4














          I think my problem is actually described in the Babel docs. https://babeljs.io/docs/en/config-files#monorepos says that the solution is to use a babel.config.js file rather than a .babelrc file. Deleting .babelrc and putting this in babel.config.js does seem to work:



          module.exports = function (api) {
          api.cache(true);

          const presets = ["@babel/preset-env"];
          const plugins = ;

          return {
          presets,
          plugins
          };
          }





          share|improve this answer































            0














            This method will prevent the loading of your babelrc file, because your file is not in the root package. You can simply change your npm script to use following :



            "scripts": {
            "build": "browserify a/index.js -t [babelify --presets [@babel/preset-env] ] --outfile bundle.js"
            }





            share|improve this answer























              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53341651%2fyarn-workspaces-and-browserify-package-json-in-subfolder-breaks-the-build%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              4














              I think my problem is actually described in the Babel docs. https://babeljs.io/docs/en/config-files#monorepos says that the solution is to use a babel.config.js file rather than a .babelrc file. Deleting .babelrc and putting this in babel.config.js does seem to work:



              module.exports = function (api) {
              api.cache(true);

              const presets = ["@babel/preset-env"];
              const plugins = ;

              return {
              presets,
              plugins
              };
              }





              share|improve this answer




























                4














                I think my problem is actually described in the Babel docs. https://babeljs.io/docs/en/config-files#monorepos says that the solution is to use a babel.config.js file rather than a .babelrc file. Deleting .babelrc and putting this in babel.config.js does seem to work:



                module.exports = function (api) {
                api.cache(true);

                const presets = ["@babel/preset-env"];
                const plugins = ;

                return {
                presets,
                plugins
                };
                }





                share|improve this answer


























                  4












                  4








                  4







                  I think my problem is actually described in the Babel docs. https://babeljs.io/docs/en/config-files#monorepos says that the solution is to use a babel.config.js file rather than a .babelrc file. Deleting .babelrc and putting this in babel.config.js does seem to work:



                  module.exports = function (api) {
                  api.cache(true);

                  const presets = ["@babel/preset-env"];
                  const plugins = ;

                  return {
                  presets,
                  plugins
                  };
                  }





                  share|improve this answer













                  I think my problem is actually described in the Babel docs. https://babeljs.io/docs/en/config-files#monorepos says that the solution is to use a babel.config.js file rather than a .babelrc file. Deleting .babelrc and putting this in babel.config.js does seem to work:



                  module.exports = function (api) {
                  api.cache(true);

                  const presets = ["@babel/preset-env"];
                  const plugins = ;

                  return {
                  presets,
                  plugins
                  };
                  }






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 23 '18 at 15:38









                  dumbmatterdumbmatter

                  5,13042561




                  5,13042561

























                      0














                      This method will prevent the loading of your babelrc file, because your file is not in the root package. You can simply change your npm script to use following :



                      "scripts": {
                      "build": "browserify a/index.js -t [babelify --presets [@babel/preset-env] ] --outfile bundle.js"
                      }





                      share|improve this answer




























                        0














                        This method will prevent the loading of your babelrc file, because your file is not in the root package. You can simply change your npm script to use following :



                        "scripts": {
                        "build": "browserify a/index.js -t [babelify --presets [@babel/preset-env] ] --outfile bundle.js"
                        }





                        share|improve this answer


























                          0












                          0








                          0







                          This method will prevent the loading of your babelrc file, because your file is not in the root package. You can simply change your npm script to use following :



                          "scripts": {
                          "build": "browserify a/index.js -t [babelify --presets [@babel/preset-env] ] --outfile bundle.js"
                          }





                          share|improve this answer













                          This method will prevent the loading of your babelrc file, because your file is not in the root package. You can simply change your npm script to use following :



                          "scripts": {
                          "build": "browserify a/index.js -t [babelify --presets [@babel/preset-env] ] --outfile bundle.js"
                          }






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 23 '18 at 16:52









                          Camille VienotCamille Vienot

                          40124




                          40124






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53341651%2fyarn-workspaces-and-browserify-package-json-in-subfolder-breaks-the-build%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Guess what letter conforming each word

                              Port of Spain

                              Run scheduled task as local user group (not BUILTIN)