thlorenz / browserify-shim

📩 Makes CommonJS incompatible files browserifyable.
MIT License
934 stars 87 forks source link

browserify-shim error when node_modules folder is a symlink #208

Closed akalongman closed 8 years ago

akalongman commented 8 years ago

On the production server node_modules folder is a symbolic link for continuous deployment purposes. When I run gulp command, I got many errors like this:

Error: Unable to find a browserify-shim config section in the package.json for /home/web/www/persist/node_modules/jquery-ui/jquery-ui.js while parsing file: /home/web/www/persist/node_modules/jquery-ui/jquery-ui.js]
  filename: '/home/web/www/persist/node_modules/jquery-ui/jquery-ui.js'
. . .

If I move node_modules in project folder, build process is successfull. How to solve this problem?

This question on StackOverflow: http://stackoverflow.com/questions/36559378/browserify-shim-error-when-node-modules-folder-is-a-symlink

package.json file

{
    "private": true,
    "devDependencies": {
        "gulp": "^3.8.8"
    },
    "dependencies": {
        "bootbox": "^4.4.0",
        "bootstrap-daterangepicker": "^2.1.19",
        "bootstrap-sass": "^3.0.0",
        "browserify-shim": "^3.8.12",
        "eonasdan-bootstrap-datetimepicker": "^4.15.35",
        "font-awesome": "^4.5.0",
        "jquery": "^2.2.3",
        "jquery-ui": "^1.10.5",
        "jquery.maskedinput": "^1.4.1",
        "laravel-elixir": "^4.0.0",
        "moment": "^2.12.0",
        "select2": "^4.0.2"
    },
    "browserify": {
        "transform": ["browserify-shim"]
    },
    "browserify-shim": {
        "jquery": "$",
        "bootstrap": {
            "depends": ["jquery:jQuery"],
            "exports": "bootstrap"
        },
        "select2": {
            "depends": ["jquery:jQuery"],
            "exports": "$.fn.select2"
        },
        "bootbox": {
            "depends": ["jquery:jQuery", "bootstrap:bootstrap"],
            "exports": "bootbox"
        },
        "maskedinput": {
            "depends": ["jquery:jQuery"],
            "exports": "$.fn.mask"
        },
        "daterangepicker": {
            "depends": ["jquery:jQuery", "bootstrap:bootstrap"],
            "exports": "$.fn.daterangepicker"
        },
        "eonasdan-bootstrap-datetimepicker": {
            "depends": ["jquery:jQuery", "moment:moment", "bootstrap:bootstrap"],
            "exports": "$.fn.datetimepicker"
        }
    },
    "browser": {
        "jquery": "./node_modules/jquery/dist/jquery.js",
        "jquery-ui": "./node_modules/jquery-ui/jquery-ui.js",
        "eonasdan-bootstrap-datetimepicker": "./node_modules/eonasdan-bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.js",
        "select2": "./node_modules/select2/dist/js/select2.min.js",
        "bootbox": "./node_modules/bootbox/bootbox.min.js",
        "maskedinput": "./node_modules/jquery.maskedinput/src/jquery.maskedinput.js",
        "daterangepicker": "./node_modules/bootstrap-daterangepicker/daterangepicker.js",
        "moment": "./node_modules/moment/min/moment-with-locales.min.js",
        "bootstrap": "./node_modules/bootstrap-sass/assets/javascripts/bootstrap.js"
    }
}
bendrucker commented 8 years ago

Can you get a stacktrace for that error?

thlorenz commented 8 years ago

Linking breaks browserify and shim since your projects dependencies are outside of your project tree. So when looking upwards these tools can't find the package.json of your package anymore.

So don't link your node_modules folders .. it's a bad idea anyways since you're then linked to a global in your system, i.e. it's better to have all your deps be local to your project. Not sure what your deployment purposes are, but to me it seems like whoever made that decision didn't fully understand how node/npm is supposed to work.

acao commented 5 years ago

@thlorenz yarn link/npm link is a common scenario for developing multiple, interdependent repositories at once. This is an issue for the graphiql project