Skip to content
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

webpack can't parse the webpack module #184

Closed
fresheneesz opened this issue Feb 26, 2014 · 13 comments
Closed

webpack can't parse the webpack module #184

fresheneesz opened this issue Feb 26, 2014 · 13 comments

Comments

@fresheneesz
Copy link
Contributor

I don't know if this is expected or not - its not really something i intended, but i thought i'd report it anyway. I had a require('webpack') in the script i was bundling, and when bundling got this:

../~/webpack/package.json
Module parse failed: F:\<omitted>\node_modules\webpack\package.json Line 2: Unexpected token :
| {
|   "name": "webpack",
|   "version": "1.0.1",
|   "author": {
 @ ../~/webpack/lib/Stats.js 77:11-37
@sokra
Copy link
Member

sokra commented Feb 27, 2014

You need the json-loader.

Here is webpack compiled by webpack for the browser: http://webpack.github.io/playground/

@dashed
Copy link
Contributor

dashed commented Feb 27, 2014

@sokra Oh man. That's sweet!

@fresheneesz
Copy link
Contributor Author

I'm confused, why would I need the json-loader to build a bundle that requires webpack? Node.js doesn't require any json-loader to run scripts using the webpack api, right?

That demo is pretty sweet - you should definitely put that front and center on the documentation webpage, and in the git readme. Those really help people decide to use something.

@sokra
Copy link
Member

sokra commented Feb 27, 2014

node.js can load .json files.

see webpack/docs#5. The problem is that the playground are not full featured. No chunks, because of the way the iframe is injected. No custom loaders.

@fresheneesz
Copy link
Contributor Author

So it can, another reason to make the json-loader come standard in webpack I think.

@jhnns
Copy link
Member

jhnns commented Feb 27, 2014

Well, there are two concepts clashing 😄 . node loads json files out of the box, webpack requires a loader for everything that is not pure JavaScript.

I think node loads json files because node doesn't know anything about loaders. They decided to leave it out after having burned their fingers with require.extensions. But webpack has a powerful loader mechanism which should imho be used for every file that is not pure JavaScript (and, well, JSON is not actually JavaScript 😉). So I think it's ok that webpack requires the json-loader.

@fresheneesz
Copy link
Contributor Author

As a matter of fact, JSON is pure javascript, as javascript recognizes it verbatim. In my opinion, reducing the impedance mismatch of web vs node.js is the paramount problem webpack solves, and reducing that mismatch to 0 should be the goal. : )

@jhnns
Copy link
Member

jhnns commented Mar 1, 2014

Anyway, I would be ok with both solutions. 😄

@jhnns jhnns mentioned this issue Mar 2, 2014
@altano
Copy link

altano commented Mar 2, 2014

My vote is to make this work by default if encountered in an npm package:

var package = require("./package");

so I'm with fresheneesz.

I also don't feel strongly though, and think both are okay.

sokra added a commit that referenced this issue Mar 3, 2014
clever warning for module parse errors.

#184
@sokra
Copy link
Member

sokra commented Mar 4, 2014

I added .json as default extension.

I will not make the json-loader default for three reasons:

  • It's not backward-compatible: This means it will break all applications that use json files...
  • It would be impossible/difficult/hard to understand to use another loader for json files. I. e. the json5-loader.
  • It's weird/hard to understand to make all loaders explicit and only the json-loader is default.

@sokra sokra closed this as completed Mar 4, 2014
@jhnns
Copy link
Member

jhnns commented Mar 4, 2014

I added .json as default extension

Does it mean that I can require("./package.json")?

@sokra
Copy link
Member

sokra commented Mar 4, 2014

This means require("./package") resolve to package.json. You still need the json-loader in the webpack.config.js or --module-bind json

addnab added a commit to addnab/react-starter-kit that referenced this issue Oct 29, 2015
devonzuegel pushed a commit to devonzuegel/cosmocat that referenced this issue Nov 1, 2016
@g-patel
Copy link

g-patel commented Jan 5, 2017

This means require("./package") resolve to package.json.

@sokra Even though late post here, I can't get it working without adding .json in the require. However, it works when I have have full file name including .json in the require.

godkingkns added a commit to godkingkns/react-starter-kit that referenced this issue Mar 18, 2022
osephson added a commit to osephson/saas-react-boilerplate that referenced this issue May 7, 2022
robertomartinez09515 added a commit to robertomartinez09515/react-dashboard that referenced this issue Jul 18, 2022
superdev905 added a commit to superdev905/react-dashboard that referenced this issue Jul 26, 2022
fly0305 pushed a commit to fly0305/admin-dashboard that referenced this issue Aug 14, 2022
brightmanforever022 added a commit to brightmanforever022/react-starter-kit that referenced this issue Jan 31, 2023
kranthi186 added a commit to kranthi186/react-starter-kit that referenced this issue Feb 2, 2023
goal-dev added a commit to goal-dev/react-dashboard that referenced this issue Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants