Stencil build fails when node modules include internal dependencies on JSON resource files.
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".
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.
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.
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.
I think this issue is going to be very common. I think we should just add rollup-plugin-json to stencil. Sounds good @adamdbradley?
yeah sounds good 👍
Commit 39dcfc62bd1faafe1b413e3e8ef9cdf63133307d fixes this issue.
for anyone who came here -- this seems to stopped to work 😞