Closed jsmankoo closed 8 years ago
same here, any news on this?
btw: when using webpack with json-loader my import looks like this:
var Prismic = require('json!prismic.io');
and I am getting that error here:
./~/json-loader!./~/prismic.io/lib/prismic.js
Module build failed: SyntaxError: Unexpected token ;
Apparently it's added by npm, and you need the json loader:
@erwan I've used the json loader and getting another error you can see in my last comment
@mmintel could you post a sample project that reproduces the bug so I can try it?
@erwan sure! here it is: https://github.com/mmintel/test-webpack-prismic/tree/master
@mmintel I use es6 syntax, and merely import Prismic from prismic.io works fine
@lianilu `import Prismic from 'prismic.io'´ throws the same error
@mmintel what's your version of node and npm?
$ npm -v
3.8.6
$ node -v
v6.0.0
@mmintel node -v 6.0.0 is not compatible with prismic. I tried that and got the err, and switched back to 5.X and worked. Sorry for the late reply.
@mmintel good to know, I'll do some testing to confirm that and fix it if needed.
@mmintel it appears prismic works with 6.0.0: https://travis-ci.org/prismicio/javascript-kit/jobs/129059410
Do you have an example of code that breaks with prismic and Node 6.0.0?
@erwan if you clone this repo here (https://github.com/mmintel/test-webpack-prismic) and run npm start you should get the error. I've only added:
var Prismic = require('json!prismic.io');
to this file https://github.com/mmintel/test-webpack-prismic/blob/master/src/components/Main.js
The rest comes from that yeoman generator https://github.com/newtriks/generator-react-webpack
So all that results in the following error
ERROR in ./~/json-loader!./~/prismic.io/lib/prismic.js
Module build failed: SyntaxError: Unexpected token ; in JSON at position 12
at Object.parse (native)
at Object.module.exports (/Users/mmintel/Projekte/react-webpack/node_modules/json-loader/index.js:7:48)
@ ./src/components/Main.js 26:14-40
@mmintel bit late but I believe this is an issue with json-loader (1, 2, 3)
I haven't investigated the above thoroughly but I was able to get your test repo working (https://github.com/mmintel/test-webpack-prismic) with the following:
Main.js
var Prismic = require('prismic.io');
(removed json!
prefix)
cfg/defaults.cfg
Added json-loader:
preLoaders: [{
test: /\.json$/,
loader: 'json-loader'
}...]
Node 5.6.0 npm 3.9.0 json-loader 0.5.4 prismic.io 3.1.3
using the above config helped me as well. Thank you @robinpyon.
It might be useful to layout json-loader
as a dependency for this project. The examples don't show anything like that.
Module parse failed: /home/jsmankoo/Projects/TemplatesSinglePage/node_modules/prismic.io/package.json Line 2: Unexpected token : You may need an appropriate loader to handle this file type. | { | "_args": [ | [ | "prismic.io", @ ./~/prismic.io/lib/requests.js 109:16-42 145:16-42
works just fine when used in Node.js
webpack Config var path = require('path'); var webpack = require('webpack'); var jeet = require('jeet'); var axis = require('axis'); var rupture = require('rupture'); var autoprefixer = require('autoprefixer-stylus');
module.exports = { devtool: 'eval', entry: [ 'webpack-dev-server/client?http://localhost:3000', 'webpack/hot/only-dev-server', './src/index' ], output: { path: path.join(dirname, 'dist'), filename: 'bundle.js', publicPath: '/static/' }, plugins: [ new webpack.HotModuleReplacementPlugin() ], module: { loaders: [{ test: /.js$/, loaders: ['react-hot', 'babel'], include: path.join(dirname, 'src') },{ test: /.styl$/, loader: 'style-loader!css-loader!stylus-loader' }] }, stylus: { use: [axis(), jeet(), rupture(), autoprefixer()] } };