stencil icon indicating copy to clipboard operation
stencil copied to clipboard

Stencil build fails when node modules include internal dependencies on JSON resource files.

Open mikebernard opened this issue 8 years ago • 7 comments

Stencil version:

 @stencil/[email protected]

I'm submitting a:

  • [x] bug report
  • [ ] feature request
  • [ ] support request => Please do not submit support requests here, use one of these channels: https://forum.ionicframework.com/ or https://stencil-worldwide.slack.com

Current behavior: When including libphonenumber-js node module, Unexpected token " error is thrown.

Expected behavior: Including modules that have JSON dependencies bundle without failure.

Steps to reproduce: npm install libphonenumber-js --save

In a Util.ts file import {parse, format} from 'libphonenumber-js';

Util.ts file is imported in a stencil component.

stencil build --config config/stencil.config.dev.js

Other information: Webpack solves this by using json-loader. https://www.npmjs.com/package/json-loader Rollup has a plugin for json to resolve this. https://www.npmjs.com/package/rollup-plugin-json

I have also tried to use the require( ) syntax instead. This errors on page load with "require is not defined".

mikebernard avatar Dec 28 '17 21:12 mikebernard

Hey! Thanks for opening an issue with us. We are going to look into supporting this post 1.0. Also note for team https://github.com/rollup/rollup-plugin-json should solve this.

jgw96 avatar Jan 05 '18 19:01 jgw96

Is there any way to get this working right now with the rollup-plugin-json package? I am trying to develop a wc that relies on the aws-sdk which uses JSON resources files.

SudharsanSukumar avatar Jan 08 '18 19:01 SudharsanSukumar

Hi @jgw96 ,

May you explain a bit more on how to resolve it using rollup-plugin-json?

Since stencil will bundle files and rollup is another bundler, I am confused on how to use them together.

I did the followings > npm install --save-dev rollup-plugin-json

Then created a rollup.config.js in root

import json from 'rollup-plugin-json';

export default {
    entry: 'src/components/app-home/app-home.tsx',
    dest: 'dist/bundle.js',
    format: 'iife',

    plugins: [
        json({
            // All JSON files will be parsed by default,
            // but you can also specifically include/exclude files
            include: 'node_modules/**',
        })
    ]
};

Run it > npm start

[ ERROR ] bundling: node_modules/entities/maps/entities.json, line: 1 Unexpected token

My app does not require the json file, but one of my third party library is using it.

Thank you.

franfran avatar Jan 13 '18 04:01 franfran

I think this issue is going to be very common. I think we should just add rollup-plugin-json to stencil. Sounds good @adamdbradley?

jthoms1 avatar Feb 09 '18 16:02 jthoms1

yeah sounds good 👍

adamdbradley avatar Feb 09 '18 16:02 adamdbradley

Commit 39dcfc62bd1faafe1b413e3e8ef9cdf63133307d fixes this issue.

jthoms1 avatar Feb 16 '18 16:02 jthoms1

for anyone who came here -- this seems to stopped to work 😞

ZuBB avatar Jan 30 '21 07:01 ZuBB