Coder Social home page Coder Social logo

Require-CS not working with Cajon about cajon HOT 3 CLOSED

skyrpex avatar skyrpex commented on June 20, 2024
Require-CS not working with Cajon

from cajon.

Comments (3)

jrburke avatar jrburke commented on June 20, 2024

Cajon just allows using CommonJS syntax for a module API. So, like the AMD sugar syntax just without the define() wrapper. It does not assume or shim anything around how Node handles ID resolution. In particular, it does not do the require.extensions thing that Node does to handle different code types, like coffeescript (side note, that would be extremely expensive for a front-end browser loader, doing multiple network fetches, many that would be 404s).

If you have coffeescript in the project, then the dependency IDs need to have 'cs!' prefixes for the coffeescript files, if they are to be handled by require-cs (and have require-cs installed in the project).

I believe that is the core of the question, so closing as a discussion ticket. So feel free to continue discussion here, just closing to indicate a bug fix does not need to be scheduled.

from cajon.

skyrpex avatar skyrpex commented on June 20, 2024

I'm sorry, my description was so vague that I didn't explain myself. I think there's a bug when Cajon reads the dependency list of a module. Here is a minimal complete example.

bower.json

{
  "name": "cajon-test",
  "dependencies": {
    "require-cs": "~0.5.0",
    "cajon": "~0.2.4"
  }
}

index.html

<html>
<head>
    <script src="bower_components/cajon/cajon.js"></script>
    <script>
    requirejs.config({
        paths: {
            cs: 'bower_components/require-cs/cs',
            'coffee-script': 'bower_components/coffeescript/extras/coffee-script'
        },
        // Convenient shim for CoffeeScript
        shim: { 'coffee-script': { deps: [] } }
    });

    require(['cs!main']);
    </script>
</head>
<body>
</body>
</html>

main.coffee

console.log 'Main'
require 'cs!./dep'

dep.coffee

console.log 'Dep'

If you run this example, you will see Uncaught Error: fromText eval for cs!main failed: Error: Module name "cs!dep" has not been loaded yet for context: _. Use require([]).

Cajon didn't load dep.coffee before executing main.coffee. If you convert main.coffee to it's JS equivalent, it works just fine.

from cajon.

skyrpex avatar skyrpex commented on June 20, 2024

@jrburke There's an example above that reproduces the problem, if you want to take a look...

Thanks.

from cajon.

Related Issues (15)

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.