Code Monkey home page Code Monkey logo

json-loader's Introduction

npm node deps tests coverage chat

JSON Loader

Install

npm install --save-dev json-loader

⚠️ Since webpack >= v2.0.0, importing of JSON files will work by default. You might still want to use this if you use a custom file extension. See the v1.0.0 -> v2.0.0 Migration Guide for more information

Usage

Inline

const json = require('json-loader!./file.json');

Configuration (recommended)

const json = require('./file.json');

webpack.config.js

module.exports = {
  module: {
    loaders: [
      {
        test: /\.json$/,
        loader: 'json-loader'
      }
    ]
  }
}

Maintainer


Tobias Koppers

json-loader's People

Contributors

ajhyndman avatar boxxxie avatar dandv avatar gunta avatar hairyrabbit avatar joshwiens avatar kevinzwhuang avatar lmatiolis avatar michael-ciniawsky avatar mkarajohn avatar montogeek avatar simenb avatar sokra avatar spacek33z avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

json-loader's Issues

Cannot resolve module 'json'

Hi, I am trying this, I am confident my paths are correct

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

and get this error

ERROR in ../mocks/mockApi.js
Module not found: Error: Cannot resolve module 'json' in /Users/me/ui/src/components/native/mocks
 @ ../mocks/mockApi.js 1:31-83

Alternative extensions not getting picked up by the loader?

Hello, I have json files with the extension .schema that I am attempting to load in a webpack build. The relevant webpack configuration bits are as follows:

...
  resolve: {
    ...
    extensions: ['.js'],
    modules: [path.join(root, 'src'), 'node_modules']
  },
  module: {
    rules: [
      {
        test: /\.(json|schema)$/,
        use: [{ loader: 'json-loader' }]
      },
    ...
  }
}

So, in a source file, when I import .json modules, there is no issue, but when I import a file with the .schema extension, it seems to be parsed by babel, instead, like follows:

const BlockedInfo = require('server/store/schemas/blockedinfo.schema')
1503033073253 - Origin: Worker (PID 13508)
   [Error] SyntaxError: /home/Panoplos/Documents/Development/Node.js/testing-schema/src/server/store/schemas/blockedinfo.schema: Unexpected token, expected ; (2:6)
  1 | {
> 2 |   "$id": "/BlockedInfo",
    |        ^
  3 |   "type": "array",
  4 |   "items": {
  5 |           "type": "object",
    at Parser.pp$5.raise (/home/Panoplos/Documents/Development/Node.js/testing-schema/node_modules/babylon/lib/index.js:4443:13)
    at Parser.pp.unexpected (/home/Panoplos/Documents/Development/Node.js/testing-schema/node_modules/babylon/lib/index.js:1755:8)
    at Parser.pp.semicolon (/home/Panoplos/Documents/Development/Node.js/testing-schema/node_modules/babylon/lib/index.js:1736:38)
    at Parser.pp$1.parseExpressionStatement (/home/Panoplos/Documents/Development/Node.js/testing-schema/node_modules/babylon/lib/index.js:2230:8)
    at Parser.parseExpressionStatement (/home/Panoplos/Documents/Development/Node.js/testing-schema/node_modules/babylon/lib/index.js:5817:20)
    at Parser.pp$1.parseStatement (/home/Panoplos/Documents/Development/Node.js/testing-schema/node_modules/babylon/lib/index.js:1905:17)
    at Parser.parseStatement (/home/Panoplos/Documents/Development/Node.js/testing-schema/node_modules/babylon/lib/index.js:5795:22)
    at Parser.pp$1.parseBlockBody (/home/Panoplos/Documents/Development/Node.js/testing-schema/node_modules/babylon/lib/index.js:2262:21)
    at Parser.pp$1.parseBlock (/home/Panoplos/Documents/Development/Node.js/testing-schema/node_modules/babylon/lib/index.js:2241:8)
    at Parser.pp$1.parseStatement (/home/Panoplos/Documents/Development/Node.js/testing-schema/node_modules/babylon/lib/index.js:1862:19)
    at Parser.parseStatement (/home/Panoplos/Documents/Development/Node.js/testing-schema/node_modules/babylon/lib/index.js:5795:22)
    at Parser.pp$1.parseBlockBody (/home/Panoplos/Documents/Development/Node.js/testing-schema/node_modules/babylon/lib/index.js:2262:21)
    at Parser.pp$1.parseTopLevel (/home/Panoplos/Documents/Development/Node.js/testing-schema/node_modules/babylon/lib/index.js:1772:8)
    at Parser.parse (/home/Panoplos/Documents/Development/Node.js/testing-schema/node_modules/babylon/lib/index.js:1667:17)
    at parse (/home/Panoplos/Documents/Development/Node.js/testing-schema/node_modules/babylon/lib/index.js:7163:37)
    at File.parse (/home/Panoplos/Documents/Development/Node.js/testing-schema/node_modules/babel-core/lib/transformation/file/index.js:517:15)
1503033073290 - Worker 0 exited - Exit code: 1

Any insights as to why this may be happening will be greatly appreciated.

Module build failed: SyntaxError: Unexpected token m

This is what I'm getting:

ERROR in ./src/components/config.json
Module build failed: SyntaxError: Unexpected token m
    at Object.parse (native)
    at Object.module.exports (/Users/me/my-project/node_modules/json-loader/index.js:7:48)
 @ ./src/components/Main.js 28:13-37

The relevant JSON file I'm trying to load:

{
  "redirectUri": "http://localhost:8000/webpack-dev-server/"
}

I'm requiring it via var Config = require('./config.json');. I had the same error when I did require('json!./config.json').

I have this in my list of loaders:

{
  test: /\.json$/,
  loader: 'json-loader!json-loader'
}

I got the same error when I moved the loader to the preLoaders section.

This is the version I'm using: "json-loader": "^0.5.4".

Order of json-loader in rules causing package to fail

We're running both linux and windows set-ups, depending on the order in which json-loader is included in the rules, on different operating systems, it will either pass or fail.

This order works on linux, but fails on windows.

 {
        test: /\.json$/,
        use: ['json-loader']
      },
      {
        test : /\.jsx?/,
        // include: APP_DIR,
        exclude: /node_modules\/(?!ayvri-*)/,
        use: 'babel-loader',
      },

This fails on linux but work on windows

 {
        test: /\.json$/,
        use: ['json-loader']
      },
      {
        test : /\.jsx?/,
        // include: APP_DIR,
        exclude: /node_modules\/(?!ayvri-*)/,
        use: 'babel-loader',
      },

In case you want our full webpack, it's


var webpack = require('webpack');
var path = require('path');

var APP_DIR = path.resolve(__dirname, 'src');
var BUILD_DIR = path.resolve(__dirname, 'public');

var config = {
  entry:  {
    bundle: APP_DIR + '/index.js',
    workers: APP_DIR + '/workers/index.js',    
    clientAPI: APP_DIR + '/util/clientAPI.js'
  },
  output: {
    path: BUILD_DIR,
    filename: '[name].js',
    publicPath: 'https://localhost:3000',
    library: 'AyvriClientAPI'
  },
  module : {
    rules : [
      {
        test: /\.json$/,
        use: ['json-loader']
      },
      {
        test : /\.jsx?/,
        // include: APP_DIR,
        exclude: /node_modules\/(?!ayvri-*)/,
        use: 'babel-loader',
      },

      {
        test: /\.css$/,
        use: [
            'style-loader',
            'css-loader?modules&importLoaders=1&localIdentName=[path]___[name]__[local]___[hash:base64:5]'
        ]
      }
    ]
  },
  plugins: [
    new webpack.DefinePlugin({
      'process.env': {
        'assetPath': '"//s3.amazonaws.com/doarama-viewer-production"',
        'NODE_ENV': '"production"'
      }
    }),
    new webpack.SourceMapDevToolPlugin({
      filename: '[name].js.map'
    })
  ]
};

module.exports = config;

Converting circular structure to JSON

I`m trying to build angular with webpack, and this is what i have, can somebody help me?

webpack.config.js
'use strict';

var path = require('path');
var webpack = require('webpack');

module.exports = {
  context: path.join(__dirname, '/'),
  entry: {
    app: ['./app/main.ts']
  },
  output: {
    path: path.join(__dirname, 'server/public/javascripts'),
    filename: '[name].js'
  },
  resolve: {
    extensions: ['', '.ts', '.js', '.json']
  },
  module: {
    loaders: [
      { test: /\.json$/, loader: 'json' },
      { test: /\.ts$/, loader: 'ts-loader'}
    ]
  },
  plugins: [
    new webpack.ProvidePlugin({
      'System': require('systemjs')
    })
  ]
};
error log
Module parse failed: /home/sergey/projects/vk-app/node_modules/ts-loader/index.js!/home/sergey/projects/vk-app/app/main.ts Converting circular structure to JSON
You may need an appropriate loader to handle this file type.
TypeError: Converting circular structure to JSON
    at Object.stringify (native)
    at Parser.<anonymous> (/home/sergey/projects/vk-app/node_modules/webpack/lib/ProvidePlugin.js:36:86)
    at Parser.applyPluginsBailResult (/home/sergey/projects/vk-app/node_modules/webpack/node_modules/tapable/lib/Tapable.js:48:50)
    at Parser.walkIdentifier (/home/sergey/projects/vk-app/node_modules/webpack/lib/Parser.js:684:21)
    at Parser.walkExpression (/home/sergey/projects/vk-app/node_modules/webpack/lib/Parser.js:513:40)
    at Parser.walkMemberExpression (/home/sergey/projects/vk-app/node_modules/webpack/lib/Parser.js:677:7)
    at Parser.walkExpression (/home/sergey/projects/vk-app/node_modules/webpack/lib/Parser.js:513:40)
    at Parser.walkCallExpression (/home/sergey/projects/vk-app/node_modules/webpack/lib/Parser.js:657:9)
    at Parser.walkExpression (/home/sergey/projects/vk-app/node_modules/webpack/lib/Parser.js:513:40)
    at Parser.walkExpressionStatement (/home/sergey/projects/vk-app/node_modules/webpack/lib/Parser.js:360:7)
 @ multi app

Usage of "\t" in JSON.stringify makes webpack needlessly slow

Should the returned value really be constructed with JSON.stringify(value, undefined, "\t")? Specifically the "\t" could be problematic, and slow down webpack. What's wrong with using something else, such as source for example?

In my project, I'm loading a JSON file that contains a 512x512 matrix of data. In my original file, this takes up 512 lines of text. However, the json-loader's use of JSON.stringify(value, undefined, "\t") is causing this matrix to now consume approximately 262144 lines of text. This seems to be causing webpack to take longer then necessary.

When running a webpack watch using the json-loader as is, it would take each recompile of my project approximately 6 seconds. When replacing the usage of JSON.stringify(value, undefined, "\t") with source or JSON.stringify(value), this is reduced to approximately 1 second.

Perhaps the usage of "\t" could be configured via a query option?

Enable ES2015 syntax

Add a flag/option to use the new export syntax added in ES2015 instead of module.exports.
Tools like babel used for post-processing might not be configured to recognize both module.exports/require and export/import.

This is a low priority issue, though should be (I think) easy to add.

"See webpack documentation" needs link and explanation

Don't forget to polyfill require if you want to use it in node. See webpack documentation.

Since the webpack documentation isn't doing anyone any favours, it would be great if README could link to a relevant page (target documentation page, issue discussion about target) and explain something like

When compiling with "node" as a target, require('package.json') will expect the file (package.json, in this case) to be a real, parseable JS file with a module.exports. Adding JSON loader will export the parsed JSON as a real object.

Usage question

So if I provide a json file this loader parses it into a javascript object?

If yes how would other javascript code access this object? is it in the global namespace? window.myJsonObj

Thanks

[v0.5.5] Update broke destructured import

What is Expected

import {author} from '../package.json'
console.log(author)

Doing it like this doesn't work

The default way it import specific parts of a json file works without warnings like this and it returns undefined after

What is Happening

I can import the whole json by not destructuring it

like this

import author from '../package.json'
console.log(author)

Enable use of comments in json file (use json.minify)

I think it would be convinient to use json.minify to enable and then remove the comments before parsing in json files.

I know comments are not allowed in json, but they are convinient for letting others/your future you, know whats going on without digging in source too much... especially in config files.

Suppose you are using JSON to keep configuration files, which you would like to annotate. Go ahead and insert all the comments you like. Then pipe it through JSMin before handing it to your JSON parser. - Douglas Crockford, 2012

webpack-defaults upgrade

Addition of webpack-defaults & associated refactoring as a part of the next Major release

Issue exists for status tracking across the organization.

Please do not close

Json encoding

Hi folks,

I wanted to share one concern with you.
Our .json file couldn't be processed due to some issue with Unicode encoding. Apparently, we had a Line Separator char in the string literal. It was invisible in our text editors and we found with an empirical approach. I found that answer on SO that explains why javascript fails to parse it.
I just think that it would be great to automatically escape this char in json-loader somehow. Or let a user know about the possible problem. What do you think?

Escaped unicode code points being mangled

When I run this json through the json-loader:

https://github.com/fb55/htmlparser2/blob/master/lib/entities/entities.json

I get:

63: function(module) {
    module.exports = {
        quot: 34,
        amp: 38,
        apos: 39,
        lpar: 40,
        rpar: 41,
        lt: 60,
        gt: 62,
        nbsp: 160,
        iexcl: 161
        ...
    }
}

It looks like the escaped unicode code points are being lost. I'm not exactly sure what the resulting values are, but it is neither the unescaped unicode characters nor the escaped code point sequences.

It's interesting that quot became "34" instead of just """, which is technically the correct ASCII value, but the json-loader should not be doing such conversions.

Module not found: Error: Can't resolve 'foo.json'

'use strict';

const webpack = require("webpack");
const path = require('path');

module.exports = {
entry: {
app: './build/aws.js',
libraries: ['./src/libraries.js']
},

resolve: {

modules: [
  'node_modules',
  path.resolve('./build'),
  path.resolve('.'),
  path.resolve('../../../lib')
]

},

plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: 'libraries',
filename: 'lib.bundle.js'
})
],

output: {
path: './dist',
filename: 'bundle.js'
},
rules: [
{
test: /.json$/,
use: 'json-loader'
}
],
loaders:[

     { test: /vendor\/.+\.(jsx|js)$/,
         loader: 'imports?jQuery=jquery,$=jquery,this=>window',
     },

 ]

};

AWS.JSX
import foo from 'foo.json'

setup for require statements without file extension

I'm attempting to use a number of libraries which internally require JSON files but do so without specifying the .json file extension so I'm having difficulties in setting up my loader. e.g.

e.g.
var listData = require('./list'); where list refers to a list.json in the package root. If I manually edit the index.js to var listData = require('./list.json'); then everything works as expected but editing the contents of a 3rd party library isn't a long-term solution. My JSON loader is currently configured like so:

module.exports = {
  test: /\.json$/,
  loader: 'json-loader'
}

Is there an alternative configuration I should be using in order to utilize npm packages using JSON requires without an extension?

docs(README): revert to `webpack =< v1.0.0` usage instructions

I am using Webpack version 1 and had to use the plugin to load a json file.

For some reason I was not getting anything to work until reading this Stack Overflow answer, which had different configuration (essentially different key names in the object).

Please add a warning or at least say in the README that those are instructions for Webpack 2. It would also be nice to have installation instructions for webpack v1 (if they are not already here somewhere?).

Webpack v2 config (shown in README):

module: {
  rules: [
    {
      test: /\.json$/,
      use: 'json-loader'
    }
  ]
}

Webpack v1 config (not mentioned anywhere in the README)

module: {
  loaders: [
    {
      test: /\.json$/,
      loader: 'json-loader'
    }
  ]
}

in v1, not rules, but loaders; not use, but loader

Use inputValues as shortcut?

I'm not sure if I understand the docs correctly, but shouldn't the json-loader try to read from inputValues first?

I'm using @okonet's yaml-loader which returns the parsed yaml as json string. After that the json-loader re-parses the string which is unnecessary.

Cannot find module '../maps/decode.json' from 'decode_codepoint.js'

Error

Test suite failed to run

Cannot find module '../maps/decode.json' from 'decode_codepoint.js'
at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:169:17)
at Object. (node_modules/entities/lib/decode_codepoint.js:1:106)

Package.json

{ "name": "topshelf", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "dev": "webpack -w", "start": "nodemon server/app.js", "test": "jest --coverage --silent --forceExit" }, "jest": { "presets": "react" }, "keywords": [], "author": "", "license": "ISC", "dependencies": { "@google-cloud/storage": "^1.6.0", "ajax": "0.0.4", "axios": "^0.18.0", "babel": "^6.23.0", "babel-core": "^6.26.0", "babel-jest": "^22.4.1", "babel-loader": "^7.1.3", "babel-preset-env": "^1.6.1", "babel-preset-es2015": "^6.24.1", "babel-preset-react": "^6.24.1", "body-parser": "^1.18.2", "bootstrap": "^4.0.0", "busboy": "^0.2.14", "child-process-promise": "^2.2.1", "cors": "^2.8.4", "expect": "^22.4.0", "express": "^4.16.2", "firebase": "^4.10.1", "jquery": "^3.3.1", "mongoose": "^5.0.6", "nodemon": "^1.15.1", "os": "^0.1.1", "passport": "^0.4.0", "path": "^0.12.7", "pg": "^7.4.1", "popper.js": "^1.12.9", "react": "^16.2.0", "react-bootstrap": "^0.32.1", "react-bootstrap-navdropdown-active": "^0.2.0", "react-dom": "^16.2.0", "react-dropzone": "^4.2.8", "react-router-dom": "^4.2.2", "sequelize": "^4.35.0", "webpack": "^3.11.0" }, "devDependencies": { "enzyme": "^3.3.0", "jest": "^22.4.2", "jest-cli": "^22.4.2", "json-loader": "^0.5.7" } }

Webpack

const path = require('path');

module.exports = {
entry: path.resolve('./client/public/index.js'),
output: {
path: path.resolve('./client/public/'),
filename: 'bundle.js'
},
module: {
loaders: [
{
test: /.js[x]?$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
presets: ['react', 'env', "es2015"]
}
},
{
test: /.json$/,
include: [
/node_modules/,
path.resolve(__dirname, '..')
],
loader: 'json-loader'
}
]
},
resolve: {
extensions: ['.js', '.jsx']
}
}

.Babelrc

{ "presets": ["env", "react"] }

Save as dependency?

In the README the npm command says --save which saves the dependency to dependencies in package.json. I can only think of use cases where I'd want to save it as a development dependency, i.e. I'd install it as npm install --save-dev json-loader.

So my question, why would you need this as a regular dependency?

Unhandled Promise Rejection Warning

Preface: there's a lot going on here. :/

I tried to be clever and use the package name as a CSS Prefix with @thompsongl's https://github.com/thompsongl/postcss-class-prefix.

"postcss-class-prefix": "^0.3.0",
"postcss-loader": "^0.13.0",
"json-loader": "^0.5.4",
"webpack": "^2.1.0-beta.25"
$ webpack --progress -p

 15% building modules 42/55 modules 13 active ...de_modules/css-loader/lib/css-base.js(node:73866) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Module '/Users/kevinSuttle/Code/ui-primitives-react/node_modules/json-loader/index.js' is not a loader (must have normal or pitch function)
 21% building modules 94/95 modules 1 active ...Code/ui-primitives-react/package.json

$ nvm current
v6.7.0

webpack.config.js

const pkg = require('./package.json'); 
const CssClassPrefix = `${pkg.name.split('/')[1]}_`;

// require(!json.package.json) results in
// Error: Cannot find module 'json!./package.json'

// ...
 new webpack.LoaderOptionsPlugin({
        options: {
          postcss: function (webpack) {
            return [
              require('postcss-import')({
                addDependencyTo: webpack,
              }),
              customProperties(),
              cssApply,
              autoprefixer,
              postCSSPrefix(CssClassPrefix),
            ]
          },
        },
      }

Even tried the suggestions in webpack-contrib/css-loader#145 of adding require('es6-promise') at the top of webpack.config.js, but no dice.

Seems like a race condition, but I can't be sure.

TypeError: text.forEach is not a function

Hi, I want to use json-loader with ExtractTextPlugin like this config:

rule: {
  test: /\.json$/,
  loader: ExtractJSON.extract({
    loader: [{
      loader: 'json-loader'
    }]
  })
}

That was throw this error:

ERROR in ./src/index.json
    Module build failed: TypeError: text.forEach is not a function
        at Object.<anonymous> (\node_modules\extract-text-webpack-plugin\loader.js:109:10)
        at Compiler.<anonymous> (\node_modules\webpack\lib\Compiler.js:280:10)
        at \node_modules\webpack\lib\Compiler.js:480:13
        ...

I change the json-loader return value as:

// json-loader/index.js

return "module.exports = " + '`' + JSON.stringify(value, undefined, "\t") + '`' + ";";

It's works fine, but I think it's not a good idea. Anything help for this problem ?

Thanks :)

what wrong?

module.exports = function(source) {
    this.cacheable && this.cacheable();
    console.log(source);
    var value = typeof source === "string" ? JSON.parse(source) : source;
    this.value = [value];
    return "module.exports = " + JSON.stringify(value, undefined, "\t") + ";";
}

console.log output

{}
module.exports = {};

Error: Unexpected token m in JSON at position 0

Webpack config

var webpack = require('webpack');

module.exports = {

  entry: './app/driver.js',

  externals: {
    'jquery': '$'
  },

  module: {
    loaders: [
      {
        test: /\.json$/,
        loader: "json-loader" 
      },
      {
        test: /\.html$/,
        loader: 'underscore-template-loader'
      }
    ]
  },

  output: {
    path: __dirname + '/static/js',
    filename: 'bundle.js'
  },

  plugins: [
    new webpack.ProvidePlugin({
      _: 'underscore'
    })
  ],

  resolve: {
    modulesDirectories: [__dirname + '/node_modules'],
    root: __dirname + '/app'
  },

  resolveLoader: {
    root: __dirname + '/node_modules'
  }

};

node v6.0.0

Alternative installation method

Thank you for this!

Since node 5 it is possible to just require .json files (see discussion e.g. webpack/webpack#184 and https://github.com/nodejs/node-v0.x-archive/blob/master/lib/module.js#L485 )

To reflect that, it would be nice if the README.md could point out that the same syntax (require('sample.json')) can be used, using this loader by adding

  module: {
    loaders: [
    {
      test: /\.json$/,
      loader: 'json'
    }]
  }

to your Webpack configuration file. It took me a while to figure that out while require-ing node 5 modules.

Correct usage?

The README just shows a weird require("json!./file.json"); statement. I want it to work like it does in node.

Please could we have some examples, both for config file and command line usage.

I am trying the following, but it results in an error:

$ webpack --entry ./foo.js --output-filename server.js --module-bind json

/home/simon/npm/lib/node_modules/webpack/lib/NormalModuleFactory.js:217
                        return callback(null, Object.assign({}, item, {
                                                     ^
TypeError: Object function Object() { [native code] } has no method 'assign'
    at /home/simon/npm/lib/node_modules/webpack/lib/NormalModuleFactory.js:217:33
    at onResolved (/home/simon/npm/lib/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:72:10)
    at loggingCallbackWrapper (/home/simon/npm/lib/node_modules/webpack/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
    at innerCallback (/home/simon/npm/lib/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:122:22)
    at loggingCallbackWrapper (/home/simon/npm/lib/node_modules/webpack/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
    at /home/simon/npm/lib/node_modules/webpack/node_modules/tapable/lib/Tapable.js:210:15
    at /home/simon/npm/lib/node_modules/webpack/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:38:22
    at loggingCallbackWrapper (/home/simon/npm/lib/node_modules/webpack/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
    at innerCallback (/home/simon/npm/lib/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:122:22)
    at loggingCallbackWrapper (/home/simon/npm/lib/node_modules/webpack/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
    at /home/simon/npm/lib/node_modules/webpack/node_modules/tapable/lib/Tapable.js:210:15
    at innerCallback (/home/simon/npm/lib/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:122:22)
    at loggingCallbackWrapper (/home/simon/npm/lib/node_modules/webpack/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
    at /home/simon/npm/lib/node_modules/webpack/node_modules/tapable/lib/Tapable.js:210:15
    at /home/simon/npm/lib/node_modules/webpack/node_modules/enhanced-resolve/lib/DescriptionFilePlugin.js:42:23
    at loggingCallbackWrapper (/home/simon/npm/lib/node_modules/webpack/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
    at afterInnerCallback (/home/simon/npm/lib/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:135:22)
    at loggingCallbackWrapper (/home/simon/npm/lib/node_modules/webpack/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
    at next (/home/simon/npm/lib/node_modules/webpack/node_modules/tapable/lib/Tapable.js:112:35)
    at /home/simon/npm/lib/node_modules/webpack/node_modules/enhanced-resolve/lib/ModuleKindPlugin.js:21:36
    at loggingCallbackWrapper (/home/simon/npm/lib/node_modules/webpack/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
    at innerCallback (/home/simon/npm/lib/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:122:22)
    at loggingCallbackWrapper (/home/simon/npm/lib/node_modules/webpack/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
    at /home/simon/npm/lib/node_modules/webpack/node_modules/tapable/lib/Tapable.js:210:15
    at innerCallback (/home/simon/npm/lib/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:122:22)
    at loggingCallbackWrapper (/home/simon/npm/lib/node_modules/webpack/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
    at /home/simon/npm/lib/node_modules/webpack/node_modules/tapable/lib/Tapable.js:210:15
    at /home/simon/npm/lib/node_modules/webpack/node_modules/enhanced-resolve/lib/forEachBail.js:29:14
    at loggingCallbackWrapper (/home/simon/npm/lib/node_modules/webpack/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
    at innerCallback (/home/simon/npm/lib/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:122:22)

Thanks.

Pull request

I would like to release a version to fix a loader error. Already I created a branch, but I can not do pull request (perhaps not have permission). Who can help me? The fix is ​​to avoid the error "Unexpected token m in JSON at position 0" that the loader generates the Angular 2 project

Support sourcemaps

Title speaks for itself I think. There are two possible scenario's:

  • the loaded JSON was native JSON (without a sourcemap provided), which should result in a sourcemap that maps the JSON object in the outputted code to the original file
  • the loaded JSON was the result of another pre-processing step (with an accompanying sourcemap), which should result in a new sourcemap that maintains the mappings of the previous sourcemaps, but combined with the wrapper code of this loader.

Add support for webpack2

(node:38259) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Module '/node_modules/json-loader/index.js' is not a loader (must have normal or pitch function)

webpack@^2.1.0-beta.25

Error when trying to require a JSON file

Webpack version: 0.12.2

I'm getting this error:

ERROR in dir/~/json-loader!dir/embedded/config.json
    Module build failed: SyntaxError: Unexpected token m
        at Object.parse (native)
        at Object.module.exports (dir/node_modules/json-loader/index.js:7:48)
     @ dir/embedded/includers/index.js 12:21-51

and in the includers/index.js I have this line:

var embeddedConfig = require("json!../config.json");

After checking, the problem is that the json-loader gets called two times, and the first one returns the expected outcome: "module.exports = {....}" but the second time it has "module.exports = {....}" as a source, so it tries to parse the string to JSON and then it fails because it's not a valid JSON.

Is anyone else getting the same error or did I do something wrong in the configuration?

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.