Skip to content

This seems to be a pre-built javascript file. #1617

Closed

Description

@ccorcos

I have seen some issues about this relative to Quill, but interested in the problem more generally.

WARNING in ../~/jasmine-promises/dist/jasmine-promises.js
Critical dependencies:
1:113-120 This seems to be a pre-built javascript file. Though this is possible, it's not recommended. Try to require the original source to get better results.
 @ ../~/jasmine-promises/dist/jasmine-promises.js 1:113-120

I understand thats its better to let webpack compile the source files as opposed to the distribution files, but how is this supposed to generally work? For example, in almost all of my projects, I use the webpack configuration to set a root for my project to resolve. This was I can specify absolute paths to all my files and move files around trivially with a find-replace-all. I may also have some specific loaders in my configuration to read the text from html files and minify them before passing the string into js through the require statement. I've also had a huge pain getting my sass loader to work just right due to issues with url paths. But my point is that if I were to publish a project and someone were to require the source files rather than a distribution file, then odds are, they will not have the proper configuration for it to work...

Is there a plan or a solution to this?

I think it would be worthwhile to come up with some sort of generic configuration that everyone can use and thus be compatible across the board. Just an idea.

Activity

  1. IngwiePhoenix commented on Nov 17, 2015

    @IngwiePhoenix

    If i remember, there was a plugin that would allow a sub-project to define proper loaders and partially add to the webpack config.

    It generally seems to be a problem that "sharing" webpack-able code will always require a specifi set of configs.

    For now, all you can do is document which loaders the peer needs, or use that plugin. i cant search for it atm, school blocks NPM for no good reason. :/

  2. ccorcos commented on Nov 17, 2015

    @ccorcos
    Author

    lol. sounds like your school is really trying to hinder your education ;)

  3. benvinegar commented on Jan 12, 2016

    @benvinegar

    So, I just ran into this problem w/ raven-js. We are building a dist/raven.js with Browserify that injects a version string extracted from package.json. I don't want people to load the original source, I want them to load this version. But Webpack complains with this warning.

    I find this pretty irritating because many libraries are built and loaded with Webpack just fine without warnings, e.g. jQuery. It appears that Webpack really only complains about Browserify-built libraries. If you don't want to drop this warning, it would be great if there was a way library authors could somehow suppress it.

    In the meantime, it appears my only solution is to hardcode the version string into raven-js's original source.

  4. diroussel commented on Jan 12, 2016

    @diroussel

    +1 same issue with raven-js here.

  5. dgieselaar commented on Feb 2, 2016

    @dgieselaar

    Any way to at least suppress this warning until the authors get their libraries fixed?

  6. tbroyer commented on Feb 3, 2016

    @tbroyer

    Just ran into this warning when depending on js-priority-queue. This project is written in CoffeeScript and uses browserify to generate a pure-JS UMD module. Being able to silence the warning (as I don't think js-priority-queue is at fault) would be great.

  7. ericelliott commented on Feb 9, 2016

    @ericelliott

    IMO, unless / until there is an easy way for Webpack to use the correct config for the library source, this warning is more a nuisance than a help. Trying to build our library source with incompatible configs is not going to make happy users.

  8. puppybits commented on Feb 9, 2016

    @puppybits

    Doesn't noParse handle this? Or the resolver plugin to tweak the import when reading the package.json.

  9. ericelliott commented on Feb 9, 2016

    @ericelliott

    @puppybits Aren't both of those solutions for library consumers to eliminate the warning? Why is it the library author's responsibility to teach users about this Webpack quirk?

    IMO, this warning should not be generated by default for vendor libraries.

  10. IngwiePhoenix commented on Feb 9, 2016

    @IngwiePhoenix

    You have it all wrong...

    As a library author, you shouldn't even have your users require a bundled script, but let the user's package manager lay out packages instead. Plus, if one included a bundled version, and that included a module that is also already included, you'd bubble up the size of the source.

    You only distribute the bundled versions as standalone versions for oldschool usage in html tags, but give the user the actual entrypoint of th elibrary to require.

    ./proj/
    ├── dist
    │   ├── mylib.js
    │   └── mylib.min.js
    ├── index.js
    ├── lib
    │   ├── a.js
    │   ├── b.js
    │   └── c.js
    └── package.json
    

    package.json's main field should point to index.js, whilst when using oldschool script tags, you should use stuff within the dist folder.

    Unfortunately, there are quite a lot of projects that dont get this right...

  11. ericelliott commented on Feb 9, 2016

    @ericelliott

    @IngwiePhoenix

    That's a great idea, but as mentioned in this thread, library authors may use a different configuration, or even an entirely different build tool, making our source files incompatible with the library user's build configuration. Do you have an elegant solution to that problem? If so, I'm all ears...

  12. IngwiePhoenix commented on Feb 9, 2016

    @IngwiePhoenix

    @benvinegar Why?

    function getVersion() {
      var currPath = __dirname;
      while(!fs.existsSync(path.join(currPath, "package.json"))) {
        currPath = path.join(currPath, "..");
      }
      var jsonFile = path.join(currPath, "package.json");
      var pkg = JSON.parse(fs.readFileSync(jsonFile, "utf8"));
      return pkg.version;
    }

    No hardcoding at all... If you want to use it within webpack, you could also just require your package.json - same should go for Browserify.

    function getVersion() {
      // put json-loader in your config, otherwise webpack will complain. Don't know the way for Browserify.
      return require("./package.json").version:
    }
  13. ericelliott commented on Feb 9, 2016

    @ericelliott
  14. IngwiePhoenix commented on Feb 9, 2016

    @IngwiePhoenix

    @ericelliott You mean if a library wants to make webpack aware of a different set of configurations for the library?

    For now, all I could think of is exploiting the loader list.

    var libConfig = require("someLib/webpack.config");
    // ...
    module.exports = {
      module: {
        loaders: []
          .concat(libConfig.loaders)
          .concat([
            // ... your loader settings
          ])
      }
    }

    A loader let's you define things such as include and exclude. Using include, you could export:

    module.exports = {
      loaders: [
        {
          test: /\.js$/,
          loader: "babel",
          include: [
            path.join(__dirname, "lib/whatever.js")
          ]
        }
      ]
    }

    Not elegant, thats why I called it exploiting. But it would definitively work. This exported loader list would only apply the babel loader to the specified file.

    There is no way of sharing configurations whatsoever. A plugin could spawn a child-compiler and add the results of that into the parent's module tree...but in one way or another it would feel a bit like a hack too.

    Frankly peaking, this is the same situation as platform dependant code in C/C++ - its hard to write platform independent code. That is why you are best off making your code tool-independent...but, the javascript land just has too many of these, so I can see this being hard. But yeah, thats one solution.

  15. 3 remaining items

  16. cchamberlain commented on Apr 29, 2016

    @cchamberlain

    @Plestik - Using the loader exclude node_modules only ensures that things in node_modules will not be compiled by a specific loader, however webpack will still attempt to resolve the module and bundle it per its runtime:

    image

    To exclude node_modules from webpack's runtime you must use externals with something like #839 (comment):

    import packageJSON from './package.json'
    const { dependencies = {}, devDependencies = {}, peerDependencies = {}, optionalDependencies = {} } = packageJSON
    const dependencyNames = Array.from(new Set( [ ...Object.keys(dependencies)
                                                , ...Object.keys(devDependencies)
                                                , ...Object.keys(peerDependencies)
                                                , ...Object.keys(optionalDependencies)
                                                ] ))
    const externals = dependencyNames.reduce((externals, name) => ({ ...externals, [name]: true }), {})
    export default { externals 
                   , /** rest of config here */
                   }
  17. cchamberlain commented on Apr 29, 2016

    @cchamberlain

    @ericelliott @IngwiePhoenix

    Through much hardship I've come to the following workflow in most all of my library projects:

    • I bundle libraries as a last resort since this is in general handled better by the consumer app. If I do bundle a library, I'd bundle it to lib/browser.js and force consumers to import with my-proj/lib/browser. Server side node has no use for bundled libs and in general these bundles are going to cause a lot of problems with different versions of things being used in an app.
    • I put every bit of source code in my src directory. I often see examples where people have a src directory that they compile to their lib directory and then outside of it in the root of the project they will have source files (index.js, server.js, client.js). This makes no sense to me because it forces you to write varying levels of JavaScript and include babel-register's and other things. If you just stick those files inside your src directory and create a src/lib directory, you can write all ES6+ and compile it all at once. I would love to know a good reason for sticking loose files in the root of a project that you have to write ES5 source for.
    • src/lib is for universal JS. I compile it with babel directly via "build": "babel src/lib -d lib" in my npm scripts section.
    • For library projects, I always drop in the following items which lets me run npm start when I'm developing (using npm link from a consuming app). npm run release cleans, builds, publishes a new version and publishes the projects gh-pages site automatically using esdoc.

    package.json

      "main": "lib/index.js",
      "files": [
        "lib",
        "doc"
      ],
      "scripts": {
        "start": "babel src/lib -d lib --watch",
        "prebuild": "rimraf build",
        "build": "babel src/lib -d lib",
        "predoc": "rimraf doc",
        "doc": "esdoc -c ./esdoc.json",
        "prerelease": "npm run build",
        "release": "npm version patch && npm publish",
        "postrelease": "npm run release-doc",
        "prerelease-doc": "npm run doc",
        "release-doc": "git subtree push --prefix doc origin gh-pages",
        "postrelease-doc": "git commit -am \"doc-release\" && git push --follow-tags",
        "upgrade": "ncu -a && npm update",
        "test": "echo \"who needs tests when you put asserts everywhere\" && exit 1"
      },
      "dependencies": {
        "chai": "^3.0.0"
      },
      "devDependencies": {
        "babel-cli": "^6.0.0",
        "babel-preset-es2015": "^6.0.0",
        "babel-preset-stage-0": "^6.0.0",
        "esdoc": "^0.4.6",
        "esdoc-es7-plugin": "0.0.3",
        "rimraf": "^2.5.2"
      },

    .gitignore

    /lib/
    
    # ...
    

    .npmignore

    /src/
    .babelrc
    .eslintrc
    .gitattributes
    .gitignore
    

    esdoc.json

    {
      "source": "./src/lib",
      "destination": "./doc",
      "index": "./README.md",
      "package": "./package.json",
      "coverage": true,
      "includeSource": true,
      "plugins": [
        {"name": "esdoc-es7-plugin"}
      ]
    }
    • The only way I've found to be sure that I'm not reincluding extra files and that my library still gets all its dependencies in server and browser environments is to make my libraries export factories that take all their heavy vendor dependencies and return the library. This is not very popular in most libraries but better adheres to inversion of control and will not break everyone's applications when React does something like jump from 0.14.0 to 15.0.0 (whats semver say about jumping 15 versions anyway? 😈 ) and you are hard bundling in the 0.14.0 version and now consumer apps have two copies of React. It may be prone to not locking down a specific version of React or other libraries but you can typically detect that pretty easy and call it out if its a big deal.

    src/lib/index.js

    export default ({ React }) => {
      if(!React) throw new Error('React is required by my-lib')
    
      const { Component, PropTypes } = React
      const IS_BROWSER = typeof window === 'object'
    
      if(IS_BROWSER) {
         // BROWSER SPECIFIC STUFF
      }
    
      return props => (
        <div>My library component</div>
      )
    }

    This pattern tends to work better for me, the smaller I make my libraries (less dependencies). I will likely switch things up a bit soon with Webpack 2's systemjs chunking support but for now this is what I use across the board, and I work on 15 or so libraries simultaneously (all linked and using babel watch via my npm start script). The added benefit is you get the same benefits as webpack alias by just shoving your bits of application logic into its own module, except you don't need to worry about the whole thing blowing up when imported from a non-webpacked module (webpack isomorphic stuff made me sick to my stomach).

    My projects all linked and hot reloading eachother via plain old babel
    image

    If there are holes in my logic, please let me know! I'm constantly trying to improve my system generically and apply it horizontally to all my projects so I'd be appreciative for any third-party perspectives.

  18. IAMtheIAM commented on May 26, 2016

    @IAMtheIAM

    @cchamberlain What is that cool multi console screen with the green text? :-) What is the need for seeing 15 console outputs at once anyway?

  19. cchamberlain commented on May 26, 2016

    @cchamberlain

    Not to off topic but..
    @IAMtheIAM - This is a theme I configured for ConEmu (Windows 10, msys2, zsh) running in quake mode full config here. I often split out modular bits of apps into their own packages, then npm link them into my main app. I then use babel src/lib -d lib --watch on each of them to live rebuild all of them at the same time. Once they are mature I npm install them and make room for new ones.

  20. mverderese commented on Jun 3, 2016

    @mverderese

    To suppress the warning (with quill for example) just add the following to your webpack config:

    ...
    module: {
        noParse: /node_modules\/quill\/dist\/quill.js/,
        loaders: [{
        ...
        }]
    }
    ...
  21. bebraw commented on Jan 22, 2017

    @bebraw
    Contributor

    Closing as a solution (module.noParse) was presented.

  22. gaearon commented on Feb 11, 2017

    @gaearon
    Contributor

    Unfortunately this doesn’t solve the problem for Create React App users who have no way to change the configuration. So for them the warnings are entirely non-actionable. I wish there was a way to mute this warning in particular, rather than ignore all warnings (which ideally should fail the CI unlike this one).

  23. bebraw commented on Feb 11, 2017

    @bebraw
    Contributor

    @gaearon Can you set up a separate issue for the feature request?

  24. gaearon commented on Feb 11, 2017

    @gaearon
    Contributor

    Yea sure.

  25. gaearon commented on Feb 11, 2017

    @gaearon
    Contributor

    Filed #4263

  26. added a commit that references this issue on Mar 23, 2017
  27. asmundwego commented on May 3, 2017

    @asmundwego

    The warning itself is not the problem here. The reason it shows a warning is that the source for the npm should not be ready minified code! Hiding the warning just ignores the problem, it does not fix it! The real problem is that if something fails when running in the browser, the console outputs cryptic errors referencing minified method names and properties in the stack trace. Like "Uncaught TypeError: Cannot read property 'nb' of null at Cb (...) at dc (...) at Object.fc ....." This makes it impossible to know what went wrong, and very hard to debug.

  28. ericelliott commented on May 4, 2017

    @ericelliott

    @asmundwego minified isn't the same as "pre-built", and AFAIK, this warning is not just for minified bundles.

  29. xr0master commented on Jun 5, 2018

    @xr0master

    Still didn't understand how to change my library. I use TypeScript. So I need to build a special build for webpack and after this to build another build for the html integration? Too many moves for open source libs...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions