RaveJS / rave

Zero-configuration application bootstrap and development
278 stars 8 forks source link

Problem loading JSON file. #66

Closed teehemkay closed 9 years ago

teehemkay commented 9 years ago

I'm doing something like:

var foo = require('./foo.json');

And I get the following error message: Uncaught SyntaxError: Unexpected token :

But rave doesn't have a problem loading package.json.

At first I thought it was because I was running RaveJS in debug mode and the error seemed to occur when evaluating the following JSON payload as a module at line 2651 in rave.js:

"__rave_node(function (require, exports, module, global) {{
  "foo": "bar"
}

})

//# sourceURL=http://localhost:1337/test.json
"`

But I'm getting the same error even when RaveJS is not in debug mode.

I've created a small package to reproduce the issue

unscriptable commented 9 years ago

Hey @teehemkay,

You need to npm install --save rave-load-json or bower install --save rave-load-json.

I guess it might seem weird to some folks that rave can't load your json files when it can load its own. :) I'm open to suggestions and counter arguments for this, but here was my line of thinking when I decided to not load json by default:

  1. Rave's private json loader is likely simpler (smaller, faster) than the one that end users will need. Why bloat the user's application with code they may not even use?
  2. It will be strange to AMD users (but perhaps not node users) that rave can load json without assistance, but not css or text files.

Thoughts?

-- John

teehemkay commented 9 years ago

Hey @unscriptable

Thanks for the clarification.

Weird it is :-)

Well, I would vote for Rave to be able to load json by default because it's basically javascript (and node does load json by default). CSS and text file on the other hand are a totally different matter.

But the documentation is now (?) very clear about how to load json so works for me as is.

Thanks.

gregturn commented 9 years ago

I think it would be handy for Rave to have its existing default status the way it is, but offer some other "starting points". An analog would be the way Gentoo linux has different stages. At the beginning, Gentoo Stage 1 requires you build EVERYTHING, including gcc. But most people today, start at stage 3 where gcc, the kernel, and even some base packages are pre-built for the machine you're on.

In similar, rave-starter can be what it is, but if people want to get off the ground with JSON loading (and whatever other features make sense for a pre-loaded Rave-based app), then rave-starter-something would be handy.

Spring Boot has:

Effectively, all the developer needs do is grab the last one, and all of them are pulled in to the app. People still have the freedom to pull in items one-by-one with Boot, but these convenient starters speed up the process for building standard apps.

I'm a JavaScript newbie (and node/bower newbie) so I don't know what is a good recommended grounding of tools are desired for a "stage 2" rave level. I guess JSON loading has been effectively nominated in this issue.

unscriptable commented 9 years ago

Another idea: rave could discover the installed rave-load-* extensions, but not load or use them unless they're actually used in code.

The rave-amd-plugins extension almost works like this already. The rave-amd-plugins extension installs a set of loader hooks that detect AMD plugin syntax and delegates to the appropriate AMD plugin. There's really no need to preload the plugin (but that's what rave does at the moment).

A rave-load-auto extension (bikeshedding welcome) could do something similar. If users want auto-detection of extensions, they would incur the byte and computation cost of only the rave-load-auto extension (minor). The rave-load-auto extension would be aware of the other rave-load-* extensions and only load/bundle them if needed.

Thoughts?

teehemkay commented 9 years ago

+1 on automatic discovery and lazy loading.