These are chat archives for stealjs/steal

20th
Feb 2017
Sunil George
@georgesunil81
Feb 20 2017 15:15
Need help with an error message I am getting when using a library that uses CommonJS syntax. Here is the error I get -
Uncaught TypeError: require is not a function
    at index.js:3
    at doEval (steal.js:4899)
    at __eval (steal.js:4845)
    at Loader.exec [as __exec] (steal.js:3208)
    at load.metadata.execute (steal.js:3974)
    at linkDynamicModule (steal.js:3537)
    at linkDynamicModule (steal.js:3531)
    at link (steal.js:3397)
    at Object.execute (steal.js:3716)
    at doDynamicExecute (steal.js:1955)
The line in the npm library that is causing the error is -
var BraintreeError = require('../lib/braintree-error');
I am using StealJS version "steal": "^0.16.35"
I think StealJS handles CommonJS syntax also.
Sunil George
@georgesunil81
Feb 20 2017 15:25
Has anybody come across this kind of issue? Do I need to mention anything specific in my package.json for StealJS to be able to handle CommonJS syntax?
Sunil George
@georgesunil81
Feb 20 2017 15:40
Am I missing something? Please let me know.
Gira Minus
@gKreator
Feb 20 2017 15:43
Do you have a link to the braintree js file?
Sunil George
@georgesunil81
Feb 20 2017 15:48
It is an npm package. Let me provide the install info here shortly -
npm install braintree-web
Here are the specific files I am loading from within the braintree-web using StealJS
      "braintreeClient": "node_modules/braintree-web/client/index.js",
      "braintreeHostedFields": "node_modules/braintree-web/hosted-fields/index.js"
At line 3 within index.js is where I am getting the error "require is not a function" at runtime!
Sunil George
@georgesunil81
Feb 20 2017 16:08
I think I found where the issue might be. We have the following lines in the package.json -
      "braintreeClient": {
        "format": "global",
        "deps": [
          "jquery"
        ]
      },
      "braintreeHostedFields": {
        "format": "global",
        "deps": [
          "jquery"
        ]
      },
I think the "format" specification is clashing.
Sunil George
@georgesunil81
Feb 20 2017 16:21
Is there any particular format I need to specify for CommonJS?
Sunil George
@georgesunil81
Feb 20 2017 17:00
I removed format: global from my meta spec and it resolved the "require is not a function" error!
But, now I get a bunch of 404s -
GET http://localhost:8080/lib/braintree-error.js?version=1487609901880 404 (Not Found)
GET http://localhost:8080/client.js?version=1487609901880 404 (Not Found)
GET http://localhost:8080/get-configuration.js?version=1487609901880 404 (Not Found)
GET http://localhost:8080/lib/throw-if-no-callback.js?version=1487609901880 404 (Not Found)
GET http://localhost:8080/lib/deferred.js?version=1487609901880 404 (Not Found)
So, it is now not able to find the files being "required" in the index.js file.
I am definitely missing something. Please help.
Sunil George
@georgesunil81
Feb 20 2017 17:09
Anybody?
Sunil George
@georgesunil81
Feb 20 2017 17:15
Looks like it trying to find the "required" files from localhost rather than from localhost/node_modules/...
Anyone, please let me know how to resolve this? Thanks in advance.
Sunil George
@georgesunil81
Feb 20 2017 17:31
Here are the lines from braintree-web index.js file that are causing the above 404 URLs -
var BraintreeError = require('../lib/braintree-error');
var Client = require('./client');
var getConfiguration = require('./get-configuration').getConfiguration;
These are relative paths and should be resolved correctly. Not sure why the 404s then, anybody, any ideas, any hints?
seasoup
@seasoup
Feb 20 2017 20:49

seasoup @seasoup Feb 16 17:59
when i use bundle assets: true in my steal-build config it bundles my node_modules assets (glyph icons and font awesome fonts) into /dist/node_modules but my app files into /dist/bundles/moduleName. I'd like them built into the same directory so that I can copy those files up to the server and point apache at that folder.
advice?

Matthew Phillips @matthewp Feb 17 04:20
they are built into the same directory, /dist :grinning:
the idea is that dist is the folder you can publish to your apache server

but the index.html file is built into dist/bundles/main, so if we point apache there, you can't reach distilled/node_modules
seasoup
@seasoup
Feb 20 2017 21:02
the line before this one is my question, not part of Matthews response....