Skip to content

[Packager] Requiring json file failed #773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
meetwudi opened this issue Apr 9, 2015 · 12 comments
Closed

[Packager] Requiring json file failed #773

meetwudi opened this issue Apr 9, 2015 · 12 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@meetwudi
Copy link
Contributor

meetwudi commented Apr 9, 2015

I have one config.json in the app directory, and also a List.js.

In List.js, it tries to load config.json using require (which is common in node.js). But it failed.

screen shot 2015-04-09 at 11 04 20 pm

@jaygarcia
Copy link
Contributor

I've had similar issues. I think it might have to be w/ the fact that the CommonJS implementation is not a full implementation for this framework.

@ericvicenti
Copy link
Contributor

This would be nice to support.

Internally, we would just rename to .js and add a module.exports = to make it a normal JS module.

cc @amasad

@amasad
Copy link
Contributor

amasad commented Apr 21, 2015

This landed internally, should land here next sync.

@alexaivars
Copy link

would this be the same issue as trying todo require('./package') resulting in 'unknown module' ?

@brentvatne
Copy link
Collaborator

@alexaivars - if when you do that you are trying to require package.json then yup, same thing

@alexaivars
Copy link

awesome, hope the next sync lands soon.

albertfdp added a commit to podio/podio-js that referenced this issue May 4, 2015
@amasad
Copy link
Contributor

amasad commented May 11, 2015

I didn't know that require('./package') resolved to package.json. I think it just works for hard coded .json files. @alexaivars can you confirm that it doesn't work?

@alexaivars
Copy link

@amasad I can confirm that this is true and that it's a quite common practice to require package.json in this fashion. I however first noticed this since react-native chocked when I required cheerio.

@paulgessinger
Copy link

Any news on this front?

I found that most scrapers seem to require some package that does this doe there is not much to be gained by switching to another library. #231 says the JSON requiring bug was fixed, yet I'm still getting errors with 0.4.4

@amasad
Copy link
Contributor

amasad commented May 20, 2015

@paulgessinger Yeah, require('./package.json') works, no?
The issue @alexaivars is explaining is omitting the "json".

@brentvatne brentvatne changed the title Requiring json file failed [Packager] Requiring json file failed May 31, 2015
@amasad
Copy link
Contributor

amasad commented Jun 4, 2015

Fixed this internally, should land next sync.

@cgarvis
Copy link

cgarvis commented Jun 8, 2015

+1

vjeux pushed a commit to vjeux/react-native that referenced this issue Jun 23, 2015
…d, fix bugs etc)

Summary:
@public
Fixes facebook#773, facebook#1055
The resolver was getting a bit unwieldy because a lot has changed since the initial writing (porting node-haste).
This also splits up a large complex file into the following:

* Makes use of classes: Module, AssetModule, Package, and AssetModule_DEPRECATED (`image!` modules)
* DependencyGraph is lazy for everything that isn't haste modules and packages (need to read ahead of time)
* Lazy makes it fast, easier to reason about, and easier to add new loaders
* Has a centralized filesystem wrapper: fast-fs (ffs)
* ffs is async and lazy for any read operation and sync for directory/file lookup which makes it fast
* we can easily drop in different adapters for ffs to be able to build up the tree: watchman, git ls-files, etc
* use es6 for classes and easier to read promise-based code

Follow up diffs will include:
* Using new types (Module, AssetModule etc) in the rest of the codebase (currently we convert to plain object which is a bit of a hack)
* using watchman to build up the fs
* some caching at the object creation level (we are recreating Modules and Packages many times, we can cache them)
* A plugin system for loaders (e.g. @tadeuzagallo wants to add a native module loader)

Test Plan:
* ./runJestTests.sh react-packager
* ./runJestTests.sh PackagerIntegration
* Export open source and run the e2e test
* reset cache
* ./fbrnios.sh run and click around
@facebook facebook locked as resolved and limited conversation to collaborators Jun 5, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

9 participants