webpack-contrib / json-loader

json loader module for webpack - UNMAINTAINED

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add support for webpack2

monolithed opened this issue · comments

(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

I'm using json-loader with webpack v2 and it's working for me. Do you use extract-text-webpack-plugin, and if so, what version?

Do you use extract-text-webpack-plugin, and if so, what version?

Yep, webpack@^2.1.0-beta.25 and extract-text-webpack-plugin@^2.0.0-beta.4

All dependencies

{
    "dependencies": {
        "camelcase": "^3.0.0",
        "normalize.css": "^4.2.0",
        "debug": "^2.2.0",
        "decko": "^1.1.3",
        "fuse.js": "2.5.0",
        "react": "^15.3.2",
        "react-dom": "^15.2.1",
        "react-redux": "^4.4.5",
        "react-iframe": "^0.0.4",
        "react-addons-css-transition-group": "^15.3.2",
        "react-bem-helper": "^1.1.0",
        "redux": "^3.0.5"
    },

    "devDependencies": {
        "chrome-stub": "1.5.0",

        "autoprefixer": "^6.5.1",
        "precss": "^1.4.0",
        "enzyme": "^1.1.3",

        "istanbul-instrumenter-loader": "^0.1.3",
        "babel-preset-airbnb": "^1.0.1",
        "babelify": "^7.2.0",
        "browserify": "^13.0.0",
        "babel-runtime": "^6.3.19",
        "babel-plugin-espower": "2.3.1",
        "karma": "^1.3.0",
        "karma-mocha": "^1.2.0",
        "karma-coverage": "^1.1.1",
        "karma-webpack": "^1.8.0",
        "karma-spec-reporter": "0.0.26",
        "karma-sourcemap-loader": "0.3.7",
        "karma-phantomjs-launcher": "1.0.2",
        "karma-babel-preprocessor": "6.0.1",
        "karma-browserify-preprocessor": "0.2.0",
        "mocha": "^3.1.2",
        "phantomjs-prebuilt": "2.1.13",

        "babel-core": "^6.17.0",
        "babel-loader": "^6.2.5",
        "babel-eslint": "7.0.0",
        "babel-preset-es2015": "^6.16.0",
        "babel-preset-es2016": "^6.16.0",
        "babel-preset-es2017": "^6.16.0",
        "babel-preset-react": "^6.16.0",
        "babel-preset-react-hmre": "1.1.1",
        "babel-plugin-transform-object-rest-spread": "6.8.0",
        "babel-plugin-transform-decorators-legacy": "1.3.4",
        "babel-plugin-transform-react-remove-prop-types": "0.2.10",

        "isparta": "^4.0.0",
        "express": "^4.13.3",

        "eslint": "^3.8.1",
        "eslint-loader": "^1.6.0",
        "eslint-config-pobedit": "^0.0.5",
        "eslint-friendly-formatter": "^2.0.6",
        "eslint-plugin-react": "^6.4.1",
        "eslint-plugin-babel": "^3.3.0",

        "react-addons-test-utils": "^15.3.2",

        "react-transform-hmr": "^1.0.4",
        "react-dev-utils": "^0.2.1",
        "redux-devtools": "^3.3.1",
        "redux-devtools-dock-monitor": "^1.1.1",
        "redux-devtools-log-monitor": "^1.0.11",
        "redux-devtools-inspector": "^0.8.0",
        "redux-logger": "^2.2.1",
        "redux-thunk": "^2.1.0",
        "redbox-react": "^1.2.10",
        "react-transform-catch-errors": "^1.0.2",

        "webpack": "^2.1.0-beta.25",
        "webpack-dev-middleware": "^1.2.0",
        "webpack-hot-middleware": "^2.2.0",
        "webpack-bundle-size-analyzer": "2.2.0",
        "webpack-visualizer-plugin": "0.1.5",
        "clean-webpack-plugin": "^0.1.13",
        "unused-files-webpack-plugin": "^3.0.0",
        "extract-text-webpack-plugin": "^2.0.0-beta.4",
        "optimize-css-assets-webpack-plugin": "^1.3.0",
        "imports-loader": "^0.6.5",
        "json-loader": "0.5.4",
        "find-cache-dir": "0.1.1",
        "stats-webpack-plugin": "0.4.2",
        "postcss-loader": "^0.9.1",
        "postcss-import": "^8.1.2",
        "base64-inline-loader": "^0.0.1",
        "css-loader": "^0.23.0",
        "style-loader" : "^0.13.0"
    }
}

@monolithed have you found a workaround for this yet? Let me know if I can help in any way!

@SpaceK33z seems like removing the requirement for extract-text-webpack-plugin seems to resolve the issues for json-loader — do you have more context?

@SpaceK33z

I'm using json-loader with webpack v2 and it's working for me.

Have you tried to delete your node_modules before?

@waltfy

have you found a workaround for this yet? Let me know if I can help in any way!

I rolled to a previous version 😄

Jep, just tried it again. What version of which package did you rollback to? And does the problem disappear if you don't use extract-text-webpack-plugin?

@SpaceK33z, I meant "webpack": "^1.13.2", "json-loader": "0.5.4" :)

Okay, but could you checkout if it happens without extract-text-webpack-plugin? This is crucial for me to know because if so, it is probably an issue with extract-text-webpack-plugin.

Okay, but could you checkout if it happens without extract-text-webpack-plugin?

Alas, I did not keep that state in the history of commits, sorry.

I'm going to close this since webpack v2 with json-loader does work, but it is some other package (probably extract-text-webpack-plugin since that fixed it for @waltfy) that introduces this bug.

@SpaceK33z @monolithed I think it makes sense to close the issue. I'll post any useful information I find here, it'll maybe help other people. Thanks!

👍

I'm getting the following error when loading json files with Webpack 2 and this plugin (which I don't have with Webpack 1.x:

�[1m�[31mERROR in ./src/stark-app-config.json
Module build failed: SyntaxError: Unexpected token m
    at Object.parse (native)
    at Object.module.exports (C:\LocalData\DEV\Workspace\AAH-Stark\node_modules\json-loader\index.js:7:48)
 @ ./src/app/modules/config/module.ts 12:21-62
 @ ./src/app/modules/index.ts
 @ ./src/app/app.ts
 @ ./src/main.ts
 @ multi main�[39m�[22m

Any ideas? I guess the 'm' in error is part of "module.exports" or something like that.

I'm getting the exact same as @dsebastien.

I've got the same error:

Uncaught Error: Module build failed: SyntaxError: Unexpected token m
    at Object.parse (native)
    at Object.module.exports (/home/Projects/app/node_modules/json-loader/index.js:7:48)

I'm using node in version 4.6.0

Okay I'll reopen this, but please provide some useful information so we can narrow this down. Try to remove as many plugins / loaders as possible. Especially try if removing extract-text-webpack-plugin works.

I changed my webpack.config config a bit and now it is working again. In the webpack.config I'm now using:

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

and in my files instead of importing the files like this before:

  const routesForBreadcrumb = require('json!../../config/routes.json');

I had to remove the json! at the beginning of the path like

  const routesForBreadcrumb = require('../../config/routes.json');

now it is working in node as well as in the browser environment

@crebuh see webpack/webpack#3359 for a plan on how we want to avoid the issue you had from happening again.

Closing this again since you can fix that error with the above fix.

In my case, I've doubled checked but I didn't specify the "json!" in the require call, so normally I'm only using the loader once...