Git Product home page Git Product logo

Comments (12)

idflood avatar idflood commented on August 22, 2024

Hi,

I hope I understand your question. If I'm right you are trying to require a "soap" dependency wich has been installed from npm.

If that's the case, the browser has no way to know the node modules so you have to manually copy the javascript file to the public/scripts/libs folder (the soap library will certainly be inside node_modules/soap/soap.coffee or something like this). Then you should be able to import it with 'cs!libs/soap'like you descibed in your first code block.

Normally this should be enough, but if the library is not AMD friendly then you might have to add it to the require.js config and use the !use plugin (https://github.com/idflood/ThreeNodes.js/blob/master/src/scripts/boot.coffee for an example).

As a side note require.js has been recently updated. Now the use! plugin is included but doesn't have the exact same syntax, and the !order plugin has been deprecated. I've made the required changes in the dev branch of threenodes.js if I remember correctly but it is not ready yet to be merged back on master. Meanwhile I recommend you to stay on the master branch, updating after everything has been fixed on the dev branch will be not so difficult.

from threenodes.js.

poliveira89 avatar poliveira89 commented on August 22, 2024

But,

"soap" has 2 dependencies:

  • node-expat
  • request

There is a way that I can "merge" this CoffeeScript module into one Javascript file?

from threenodes.js.

poliveira89 avatar poliveira89 commented on August 22, 2024

I have made changes that you suggested! I have copied *.js files from node_modules/soap/lib to public/scripts/soap, and added this to my code:

define [
    'use!Underscore', 
    'use!Backbone',
    'order!threenodes/models/Node',
    'order!threenodes/utils/Utils',
    'order!libs/soap/soap'
], (_, Backbone, Utils, soap) ->
    "use strict"

A new error (on browser console) appears:

Uncaught Error: Module name 'client' has not been loaded yet for context: _

"client" is a JS file from "soap" module, and "soap" call this file on his code:

var Client = require('./client').Client

What could be the problem? using "require"? "define" on my class?

from threenodes.js.

poliveira89 avatar poliveira89 commented on August 22, 2024

I have used Browserify to "merge" / "convert" an CoffeeScript File (with require("soap") on the code) into a [one] JavaScript file .. and copied to public/scripts/lib folder, and then run the ThreeNodes.js, stil not working.. now a error appear on "order.js" and the strange thing it's that I don't use "order!" plugin..

Code:

define [
    'use!Underscore', 
    'use!Backbone',
    'use!Soap',
    'order!threenodes/models/Node',
    'order!threenodes/utils/Utils'
], (_, Backbone, Utils) ->
    "use strict"

I haven't used the "Soap" object.. I only require it.. Could be because "order" is deprecated?

from threenodes.js.

idflood avatar idflood commented on August 22, 2024

Hmm, it's hard to tell what the problem is. I would like to help you more but it will be impossible this week. It's definitely not an issue with the order! plugin since it's deprecated on the new release of requirejs but not the version actually used in threenodes.

May I ask you how you configured require.js for the use! plugin in boot.coffee? Oh, and if you can create a fork of the project and push your changes there it will be easier for me to help you when I get time.

from threenodes.js.

poliveira89 avatar poliveira89 commented on August 22, 2024

I'm trying to use OneJS(https://github.com/azer/onejs) to convert Soap module into one JS file, but i had some problems with that operation, I'm still trying resolve that..

Without that JS file I can't require it, right? Or it is another option?

I'm having trouble with soap because it is a tricky module..

from threenodes.js.

poliveira89 avatar poliveira89 commented on August 22, 2024

As you suggested, I have forked the project, and made some changes.

  1. I changed the module that was using (soap) to restler
  2. I used OneJS to convert and bundle the module to a Javascript file
    • command: onejs build package.json lib-restler.js --noprocess --verbose
  3. Made a few changes in ThreeNodes.js

Then when I run node server.js, open Chrome and put localhost:3000, the following message appears on the console:

Uncaught TypeError: Module 'Rest' is undefined or does not have a `use` config. Make sure it exists, add a `use` config, or don't use use! on it           use.js:25

from threenodes.js.

poliveira89 avatar poliveira89 commented on August 22, 2024

I figured out why the error identified in the previous review, was to be triggered.
The reason was because the text editor used by me was making confusion between the tab and space, and was not making the indentation correctly.

But another question arose, using the console of Chrome Browser, I detected that require not return the expected object.
code:

define [
    'use!Underscore', 
    'use!Backbone',
    'use!Restler',
    'order!threenodes/models/Node',
    'order!threenodes/utils/Utils',
], (_, Backbone, Utils, Restler) ->
    "use strict"

    $ = jQuery

result:

Restler: function NodeNumberSimple() {
__super__: ctor
extend: function (protoProps, classProps) {
get arguments: function ThrowTypeError() { [native code] }
get caller: function ThrowTypeError() { [native code] }
group_name: ""
length: 0
name: "NodeNumberSimple"
node_name: ""
prototype: ctor
set arguments: function ThrowTypeError() { [native code] }
set caller: function ThrowTypeError() { [native code] }
__proto__: function Empty() {}

I continued to analyze the code ThreeNodes, in the console of Chrome Browser, and detected that the global variables, there is an object "restler" (lowercase name) with the contents of the module I added, I have configured the "boot.coffee" as follows manner:

require.config
  paths:
    jQuery: 'libs/jquery-1.7.2'
    jQueryUi: 'libs/jquery-ui/js/jquery-ui-1.9m6'
    Underscore: 'libs/underscore'
    Backbone: 'libs/backbone'
    use: "libs/require/use"
    text: "libs/require/text"
    order: "libs/require/order"
    Restler: "libs/lib-restler"
  use:
    'Underscore':
      attach: "_"
    'Backbone':
      deps: ['use!Underscore', 'jQuery']
      attach: "Backbone"
    'jQueryUi':
      deps: ['jQuery']
      attach: "jQuery"
    'Restler':
      attach: "Restler"

require [
  'threenodes/App',
], (App) ->
  "use strict"

  app = new App()

Expected:

restler: Object
findModule: function findModule(workingModule, uri){
findPkg: function findPkg(uri){
lib: Object
main: function (){
module: function module(parentId, wrapper){
name: "restler"
packages: Object
pkg: function pkg(/* [ parentId ...], wrapper */){
require: function mainRequire(uri){
stderr: function stderr(){
stdin: function stdin(){
stdout: function stdout(){
__proto__: Object

Why the object configured not appear properly identified in the project (with the first character capitalized, as defined in "boot.coffee")? Any questions, consult ThreeNodes that i have forked.

from threenodes.js.

idflood avatar idflood commented on August 22, 2024

Hmm, I think I've found what was wrong. The 'attach' property of the 'use' plugin looks for an object in the window object. So previously it looked for window.rest and returned nothing.

So I made these changes. In boot.coffee

require.config
  paths:
    ...
    restler: "libs/lib-restler"
  use:
    ...
    'restler':
      attach: "restler"

In Rest_WebService.coffee

define [
  ...
  'use!restler',
  ...
], (_, Backbone, Rest) -> // here the order is important and must match the order in define above 

I think this should be enough, but if I forgot something feel free to ask.

from threenodes.js.

poliveira89 avatar poliveira89 commented on August 22, 2024

I'm confused, why plugin look for an object named window.rest or window.restler, when I configured on "boot.coffee" as Restler?

By the way, another message as appear, an error from "lib-restler", but my question is, how can a JS file (from scripts folder) can require an native module from nodejs? like require("util"), I must use "deps" property on "boot.coffee"?

from threenodes.js.

idflood avatar idflood commented on August 22, 2024

The window.restler object comes from the module itself if I'm right (libs/lib-restler).

The browser doesn't know about nodejs and don't have access to these files. A possibility would be to copy the utils.js file from the nodejs source to the libs folder but I doubt it will work (it certainly use some native functions not available in the browser).

Another possibility would be to create a "fake" util class and import it instead. But looking at the source you will also need "http", "url", "zlib", ... so it isn't an option.

In fact, do you really need this library on the client side? On server side it seems nice but it looks like it's relatively easy to do rest operations with jquery: http://stackoverflow.com/questions/921942/javascript-rest-client

from threenodes.js.

poliveira89 avatar poliveira89 commented on August 22, 2024

Regarding the question about the object and name, I get it! Thanks for the reply!

For the rest, this "Issue" started because you need a SOAP client to consume a Web Service, but when I tried to convert the "Soap Module" for a JS file, I was in trouble then moved to a RESTful client to try to understand whether the problem would be in the module or tool to "convert" the module. But anyway I will require that the "Nodes" created on the client can consume SOAP and REST, in this sense was trying to use the "NodeJS modules"? What is the best approach because the various difficulties with the dependencies?

For future use of ThreeNodes.js, I just try to use the "Modules NodeJS" when I need to run code on the server, otherwise try to use "basic" scripts in the client-side, right?

from threenodes.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.