[vtkusers] VTK-js: how to read a .json file

Cristina Oyarzun coyarzunlaura at googlemail.com
Wed Jul 26 05:31:11 EDT 2017


Dear Scott and Aron,

thank you for your answers. I was indeed using an older version of Webpack,
but I already upgraded to the newest version. Unfortunately I keep getting
errors when I try to read the JSON file. To this I have to add that
although I have been using vtk for quite a long time now, I am completely
new to javascript.

If I understood correctly with webpack 2 I do not need to add anything to
the webpack.config.js to be able to read json files in the index.js. Is
this right? However, I try to read the json file with the following command
in index.js:

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

apart of that line of code I didnt write anything else related to the
json file. I got the following error:

ERROR in ./src/file.json
Module build failed: SyntaxError: Unexpected token / in JSON at position 146
    at Object.parse (native)
    at Object.module.exports (D:\VTK-JS\node_modules\json-loader\index.js:4:
49)
 @ ./src/index.js 285:13-35
 @ ./src/index.js
 @ multi (webpack)-dev-server/client?http://localhost:8080 ./src/index.js
webpack: Failed to compile.

Thank you very much!!!

Cristina



On Fri, Jul 21, 2017 at 5:50 PM, Scott Wittenburg <
scott.wittenburg at kitware.com> wrote:

> Hi Cristina,
>
> In vtk.js we now use webpack2 (in master at least, you may have picked an
> older version though), and the webpack2 documentation states that you no
> longer need a loader for json:
>
> https://webpack.js.org/guides/migrating/#json-loader-is-not-
> required-anymore
>
> Is your project also using webpack2?  In that case you shouldn't need the
> json loader.  Also, when you refer to "Build-in modules of Node.js", does
> that refer specifically to this:
>
> https://github.com/sindresorhus/builtin-modules
>
> or do you mean something else?
>
> Cheers,
> Scott
>
> On Fri, Jul 21, 2017 at 8:57 AM, Aron Helser <aron.helser at kitware.com>
> wrote:
>
>> Hi Cristina,
>> ParaViewWeb uses this webpack 1.x loader:
>> {
>>     test: /\.json$/,
>>     loader: 'json-loader',
>>   },
>> That should allow you to 'include' a json file in your javascript, and
>> then you might need to use the built-in JSON.parse() to turn it into an
>> object.
>>
>> Regards,
>> Aron
>>
>> On Fri, Jul 21, 2017 at 4:43 AM, Cristina Oyarzun via vtkusers <
>> vtkusers at vtk.org> wrote:
>>
>>> Dear all,
>>>
>>> I visualized several actors using VTK-js. Now I want to read a .json
>>> file and according to the information that it is included there assign
>>> different colors to the actors.
>>>
>>> Unfortunately as soon as I try to use the Build-in modules of Node.js I
>>> start getting errors. I didnt manage to find out how do I have to adapt the
>>> "webpack.config.js" (or the "package.json"?) so that it works.
>>>
>>> I found somewhere in a forum that it should work by adding " target:
>>> 'node' " to the webpack.config.js but it didnt. Any help would be great!
>>>
>>> Thank you!
>>> Cristina
>>>
>>> _______________________________________________
>>> Powered by www.kitware.com
>>>
>>> Visit other Kitware open-source projects at
>>> http://www.kitware.com/opensource/opensource.html
>>>
>>> Please keep messages on-topic and check the VTK FAQ at:
>>> http://www.vtk.org/Wiki/VTK_FAQ
>>>
>>> Search the list archives at: http://markmail.org/search/?q=vtkusers
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://public.kitware.com/mailman/listinfo/vtkusers
>>>
>>>
>>
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the VTK FAQ at:
>> http://www.vtk.org/Wiki/VTK_FAQ
>>
>> Search the list archives at: http://markmail.org/search/?q=vtkusers
>>
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/vtkusers
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170726/20a0f0fb/attachment.html>


More information about the vtkusers mailing list