I'm using parcel and babel. For the client-side I have used React. In server-side I have used Node Express.
Previously I load main.html
file by a router call and send it to the client as res.sendFile(main.html)
. It worked as React Entry point.
But now I have to use a template (Pug) instead of main.html
since I have to load a dynamic javascript in client-side. So I replace the main.html file with the main.pug file and move it to the dist folder by parcel build.
Now I am trying to load dynamic content into that pug template which situated inside /dist
folder. Is it possible to do such a thing because once I build the project, /dist/main.pug
file doesn't have "{}"
these place holders?. I know /dist
folder contains static files. In that case is they're any way to achieve this scenario?
I tried to load views/main.pug
file but in that case React libraries were not loading and gave me
can not use import outside of the module.
I tried other answers given to that question but not worked. So I decided to move main.pug
into the /dist
. Now React libraries are loading but not dynamic contents.
Source: (StackOverflow)
Here is my model class:
public enum Action {
RETRY, SETTINGS
}
private int imageId;
private String description;
private String actionName;
private Action action;
public NetworkError(int imageId, String description, String actionName, Action action ) {
this.imageId = imageId;
this.description = description;
this.actionName = actionName;
this.action = action;
}
public int getImageId() {
return imageId;
}
public void setImageId(int imageId) {
this.imageId = imageId;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getActionName() {
return actionName;
}
public void setActionName(String actionName) {
this.actionName = actionName;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(this.imageId);
dest.writeString(this.description);
dest.writeString(this.actionName);
}
protected NetworkError(Parcel in) {
this.imageId = in.readInt();
this.description = in.readString();
this.actionName = in.readString();
}
public static final Parcelable.Creator<NetworkError> CREATOR = new Parcelable.Creator<NetworkError>() {
@Override
public NetworkError createFromParcel(Parcel source) {
return new NetworkError(source);
}
@Override
public NetworkError[] newArray(int size) {
return new NetworkError[size];
}
};
Source: (StackOverflow)
I am trying to use Parcel Bundler as the bundler of my client files when I use React Server Side Rendering.
I have used the Parcel Middleware and assigned it with the location of my client entry point.
When I start my script, it shows that Parcel is bundling my files but then my ReactDOM.hydrate method is never called and it seems that the bundler never uses that file at all.
Here is my server.js file:
import Bundler from 'parcel-bundler';
import express from 'express';
import { renderer } from './Helpers';
const app = express();
const bundler = new Bundler(__dirname + '/index.js');
app.use(express.static('public'));
app.use(bundler.middleware());
app.get('*', (req, res) => {
const context = {};
const content = renderer(req, context);
if (context.url) return res.redirect(301, context.url);
if (context.notFound) res.status(404);
res.send(content);
});
const listeningPort = 5000;
app.listen(listeningPort, () => {
console.log(`Server is now live on port ${listeningPort}.`);
and here is my index.js file:
import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter } from 'react-router-dom';
import { routes as Routes } from './Routes';
const routes = Routes;
if (process.env.NODE_ENV === 'development')
ReactDOM.render(
<BrowserRouter>
{routes}
</BrowserRouter>,
document.querySelector('#root'));
else
ReactDOM.hydrate(
<BrowserRouter>
{routes}
</BrowserRouter>,
document.querySelector('#root'));
and this is my renderer file which basically renders the html file:
import React from 'react';
import { renderToString } from 'react-dom/server';
import { StaticRouter } from 'react-router-dom';
import { routes as Routes } from '../Routes';
const routes = Routes;
export default (req, context) => {
const content = renderToString(
<StaticRouter location={req.path} context={context}>
{routes}
</StaticRouter>
);
const lang = "en";
return `
<!DOCTYPE html>
<html lang="${lang}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="apple-mobile-web-app-capable" content="yes">
<link rel='nofollow' href="./public/plugin/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
<link rel='nofollow' href="./public/plugin/font-awesome/css/fontawesome-all.min.css" rel="stylesheet" />
<link rel='nofollow' href="./public/plugin/et-line/style.css" rel="stylesheet" />
<link rel='nofollow' href="./public/plugin/themify-icons/themify-icons.css" rel="stylesheet" />
<link rel='nofollow' href="./public/plugin/owl-carousel/css/owl.carousel.min.css" rel="stylesheet" />
<link rel='nofollow' href="./public/plugin/magnific/magnific-popup.css" rel="stylesheet" />
<link rel='nofollow' href="./public/css/style.css" rel="stylesheet" />
<link rel='nofollow' href="./public/css/color/default.css" rel="stylesheet" id="color_theme" />
</head>
<body>
<div id="root">${content}</div>
</body>
</html>
`;
};
The application runs and loads the content inside the StaticRouter but never does the Hydrate.
Source: (StackOverflow)
I want to serve tensorflow.js models in a web app built with parcel, similar to https://github.com/googlecreativelab/teachablemachine-community/tree/master/libraries/image.
I have a run.js file and a run.html as well as a folder (model1) with model.json, metadata.json and weights.bin. I am bundling all this with parcel.
The Problem is, when I import the model.json, metadata.json and weights.bin files, they are parsed, which I can't use.
I would want them in a "file" format.
I can achieve this by loading the files in the html's element, but I would like to hand the models to the user.
run.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div>Teachable Machine Image Model Local</div>
<button type="button" id="loadmodel">Load Model 1</button>
<button type="button" id="run">Start</button>
<input type="file" id="lm1">Model</input>
<input type="file" id="lmd1">Metadata</input>
<input type="file" id="lw1">Weights</input>
<script src="./run.js"></script>
</body>
</html>
run.js:
import localmodel1 from "./model1/model.json";
import localmeta1 from "./model1/metadata.json";
import localweights1 from "./model1/weights.bin";
const textFile = fs.readFileSync(__dirname + "/model1/weights.bin", "utf8");
console.log(textFile);
localModel = localmodel1;
localMetadata = localmeta1;
localWeights = localweights1;
/*
fs.readFile('./model1/weights.bin', function (err, bin) {
localweights1 = bin;
if (err) throw err;
});
*/
uploadModel = document.getElementById('lm1').files[0];
uploadMetadata = document.getElementById('lmd1').files[0];
uploadWeights = document.getElementById('lw1').files[0];
model = await tmImage.loadFromFiles(uploadModel, uploadWeights, uploadMetadata);
Source: (StackOverflow)
I'm using Parcel. I'm trying to call a function from a form oninput
event in HTML.
I keep getting an error that the function is undefined, even though I have the script tag before the form.
I simply run parcel index.html
to start the webserver with the following code:
export function formInputChanged(input: HTMLInputElement, output: HTMLOutputElement){
output.value = input.value;
}
<html>
<header>
</header>
<body>
<script src="./formChanges.ts"></script>
<form id="input_form">
<input type="range" name="min_lvr" value="20" min="0.0" max="100" step="1"
oninput="formInputChanged(this, txt_min_lvr);">
<output name="txt_min_lvr" for="min_lvr" value="min_lvr.value"></output>%
</form>
</body>
</html>
I know I can do the update inline in the HTML code, but I would like to know how to do it with an external function.
Source: (StackOverflow)
I am building a weather app so I need to grab the icon that is matching the call from API. I'm using parcel and parcel dumps all the images in dist folder. I import all the images and that gives me an object which I converted in a one dimensional Array. Because Parcel gives some extra text I can't grab the proper image.
This is the array that I can see:
[0: "/01d.b9bbb2b9.svg" 1: "/01n.2290e7c6.svg" 2: "/02d.ac486e56.svg" 3: "/02n.259589cf.svg"]
<img src="${result.weather.icon}" alt="" class="weather--icon" />//I like to render it like this.
Is there a way I can loop over an array and get only the icon that is matching result.weather.icon
??? I need to find only the 01d
or 02d
from the array.
Source: (StackOverflow)
Has anyone gotten a Typescript component working with Storybook with React and Parcel (without Create React App)?
I've been able to successfully get it without TypeScript but using Typescript has been extremely hard.
Here is a staged Codesandbox that I've gotten Storybook to work without a TypeScript component. But I can't get a TypeScript file to work
https://codesandbox.io/s/parcel-ts-storybook-eiqd8
Source: (StackOverflow)
I can't seem to get autoprefixer to work with Parcel and Svelte. I have the below code in a 'svelte.config.js'
file but it doesn't seem to be working even though it is not throwing any errors. Sass is being compiled correctly and I have a .browserlistrc
file. Any help would be appreciated!
const sveltePreprocess = require('svelte-preprocess');
module.exports = {
preprocess: sveltePreprocess({
scss: true,
postcss: {
plugins: [require('autoprefixer')]
}
})
};
I have the following devDependencies installed
"devDependencies": {
"autoprefixer": "^9.7.3",
"parcel-bundler": "^1.12.4",
"parcel-plugin-svelte": "^4.0.5",
"postcss": "^7.0.26",
"postcss-load-config": "^2.1.0",
"sass": "^1.24.2",
"svelte": "^3.16.5",
"svelte-preprocess": "^3.3.0"
}
Source: (StackOverflow)
What is the .cache folder in parcel-bundler? Is it necessary to push the .cache folder to Github ?
Source: (StackOverflow)
I am trying to annotate a data class with @parcelize and get the following error -

Here is my gradle file -
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
apply plugin: 'io.fabric'
android {
signingConfigs {
config {
keyAlias 'verte_internal_keystore'
keyPassword ANDROID_STORE_PASSWORD
storeFile file('verte_internal_keystore.jks')
storePassword ANDROID_KEY_PASSWORD
}
}
lintOptions {
abortOnError false
}
compileSdkVersion 29
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.twoverte"
minSdkVersion 21
targetSdkVersion 29
versionCode 16
versionName ".3.4.0"
multiDexEnabled true
buildConfigField "java.util.Date", "BUILD_TIME", "new java.util.Date(" + System.currentTimeMillis() + "L)"
}
File signFile = project.file('keyInfos.properties')
if (signFile.exists()) {
Properties properties = new Properties()
properties.load(new FileInputStream(signFile))
signingConfigs {
release {
storeFile file(project.file(properties['keystore.filename']))
storePassword properties['keystore.password']
keyAlias properties['keystore.alias']
keyPassword properties['keystore.password']
}
}
}
buildTypes {
....
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
productFlavors {
}
dexOptions {
javaMaxHeapSize "4g"
}
}
dependencies {
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.0.0'
configurations {
all {
exclude group: 'org.json', module: 'json'
exclude group: 'xpp3', module: 'xpp3'
}
}
//Room components
implementation 'androidx.room:room-runtime:2.2.3'
annotationProcessor 'androidx.room:room-compiler:2.2.3'
//Lifecycle components
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
implementation 'androidx.lifecycle:lifecycle-common-java8:2.1.0'
fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:1.10.19'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.cocosw:bottomsheet:1.0@aar'
implementation 'org.igniterealtime.smack:smack-android:4.1.4'
implementation 'org.igniterealtime.smack:smack-tcp:4.1.4'
implementation 'org.igniterealtime.smack:smack-im:4.1.4'
implementation 'org.igniterealtime.smack:smack-extensions:4.1.4'
implementation 'org.igniterealtime.smack:smack-sasl-provided:4.1.4'
implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
implementation 'com.amazonaws:aws-android-sdk-s3:2.6.30'
implementation 'com.squareup.okhttp:okhttp:2.6.0'
implementation 'io.michaelrocks:libphonenumber-android:8.9.14'
// Preferred for scheduling background jobs when new push notifications are received.
// It provides a JobScheduler-compatible API that works on all recent versions of
// Android (API level 14+) that have Google Play services installed.
implementation 'com.firebase:firebase-jobdispatcher:0.8.5'
implementation 'com.facebook.stetho:stetho:1.3.1'
implementation 'com.facebook.stetho:stetho-okhttp3:1.3.1'
implementation 'com.github.ksoichiro:android-observablescrollview:1.5.0'
implementation 'com.google.android.gms:play-services-auth:17.0.0'
implementation 'com.google.android.gms:play-services-identity:17.0.0'
implementation 'com.google.android.gms:play-services-location:17.0.0'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'com.google.android.gms:play-services-places:17.0.0'
implementation 'com.google.firebase:firebase-auth:19.2.0'
implementation 'com.google.firebase:firebase-core:17.2.1'
implementation 'com.google.firebase:firebase-messaging:20.1.0'
implementation 'com.google.firebase:firebase-crash:16.2.1'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'de.greenrobot:greendao:2.1.0'
implementation 'io.github.rockerhieu:emojicon:1.4.2'
implementation 'com.journeyapps:zxing-android-embedded:3.6.0'
implementation 'com.github.nkzawa:socket.io-client:0.4.2'
implementation 'com.github.chrisbanes:PhotoView:2.1.3'
implementation 'com.github.chrisbanes.photoview:library:1.2.4'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
implementation 'com.github.nkzawa:socket.io-client:0.4.2'
implementation 'net.opacapp:multiline-collapsingtoolbar:27.1.1'
implementation 'org.webrtc:google-webrtc:1.0.23295'
implementation 'com.github.clans:fab:1.6.4'
implementation 'io.branch.sdk.android:library:3.0.0'
implementation 'org.jsoup:jsoup:1.10.3'
implementation 'com.squareup.retrofit2:retrofit:2.7.0'
implementation 'com.squareup.retrofit2:converter-gson:2.7.0'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'me.relex:circleindicator:2.1.4'
implementation 'jp.wasabeef:picasso-transformations:2.2.1'
implementation 'com.github.ganfra:material-spinner:2.0.0'
implementation(name: 'appbase', ext: 'aar')
implementation(name: 'greendao', ext: 'aar')
implementation(name: 'chat', ext: 'aar')
implementation(name: 'ffmpeg', ext: 'aar')
implementation(name: 'imagecropper', ext: 'aar')
implementation(name: 'imagepicker', ext: 'aar')
implementation(name: 'webrtc', ext: 'aar')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
apply plugin: 'com.google.gms.google-services'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
repositories {
mavenCentral()
}
What am I missing? I can't seem to get the compiler to know @Parcelize annotation
I have tried to update the kotlin version, checked multiple previous questions about this issue and did not find anything relevant to assist me.
Source: (StackOverflow)
While I was build my app using Parcel, I ran into this issue. It tells me that it was not able to load the file from one of my installed package. It seems to mention webpack even though I use Parcel to bundle eveyrthing.
Here is my error code :
⚠️ Could not load source file "webpack://ReactNotifications/webpack/bootstrap" in sour
ce map of "node_modules/react-notifications-component/dist/js/react-notifications.prod.
js".
Tell me if you need any more file to help me solve this issue.
Thank you !
Source: (StackOverflow)
I try to build a small app based upon Webex web SDK, internally requiring regenerator-transform.
Here is my package.json
simple file:
{
"scripts": {
"serve": "yarn build",
"build": "parcel index.html --out-dir dist --public-url ./",
"deploy": "git subtree push --prefix dist origin gh-pages",
},
"license": "MIT",
"dependencies": {
"crypto-js": "^4.0.0",
"moment": "^2.24.0",
"urijs": "^1.19.2",
"webex": "^1.80.147"
},
"browserslist": [
"last 2 major versions and >1%"
],
"devDependencies": {
"@babel/core": "^7.8.7",
"babel-preset-es2015": "^6.24.1",
"babel-preset-es2016": "^6.24.1",
"babel-preset-stage-0": "^6.24.1"
}
}
Here is my .babelrc
file too:
{
presets : [ 'es2015', 'es2016' ]
}
It works perfectly when I use browserslist
preset latest Chrome
, but with this current query, I have this error:
[...]pkijs/src/SignedCertificateTimestampList.js: unknown Statement of type "ForOfStatement"
Full stack trace:
🚨 /Users/guillaumepotier/Sites/webex-sdk/node_modules/pkijs/src/SignedCertificateTimestampList.js: /Users/guillaumepotier/Sites/webex-sdk/node_modules/pkijs/src/SignedCertificateTimestampList.js: unknown Statement of type "ForOfStatement"
at Emitter.Ep.explodeStatement (/Users/guillaumepotier/.config/yarn/global/node_modules/regenerator-transform/lib/emit.js:587:13)
at /Users/guillaumepotier/.config/yarn/global/node_modules/regenerator-transform/lib/emit.js:323:12
at Array.forEach (<anonymous>)
at Emitter.Ep.explodeStatement (/Users/guillaumepotier/.config/yarn/global/node_modules/regenerator-transform/lib/emit.js:322:22)
at Emitter.Ep.explode (/Users/guillaumepotier/.config/yarn/global/node_modules/regenerator-transform/lib/emit.js:280:40)
at PluginPass.<anonymous> (/Users/guillaumepotier/.config/yarn/global/node_modules/regenerator-transform/lib/visit.js:111:17)
at PluginPass.<anonymous> (/Users/guillaumepotier/.config/yarn/global/node_modules/regenerator-transform/lib/util.js:28:17)
at newFn (/Users/guillaumepotier/.config/yarn/global/node_modules/@babel/traverse/lib/visitors.js:179:21)
at NodePath._call (/Users/guillaumepotier/.config/yarn/global/node_modules/@babel/traverse/lib/path/context.js:55:20)
at NodePath.call (/Users/guillaumepotier/.config/yarn/global/node_modules/@babel/traverse/lib/path/context.js:42:17)
It seems the problem is raised by regenerator-transform
and the "ForOfStatement" within a generator, I tried many babel different configs but in vain.
My parcel --version
gives me 1.12.4
Do you have any clue for that, how do you ship code with Parcel for IE11?
Source: (StackOverflow)
I'm working on updating an application so it is more maintainable. This application currently uses a very large JS file with many JS classes. I have separate the code so each JS class is in its own JS file.
I would like to use Parcel to combine all JS files into a single JS file I can link to from my index.html
.
I have added export default
to each main class. Eg. export default class MyJSClass
. Then I import classes as needed from index.js
file such as import MyJSClass from './MyJSClass.js';
The application I'm updating uses framework with structure below:
resources
|-Public
|-JS
|-singleHugeJSFile.js
|-Templates
|-index.html
I want to use Parcel and keep the same structure such as
resources
|-Public
|-JS
|-index.js // Entry point JS file
|-MyJSClass.js
|-SomeOtherClass.js
|-AnotherClass.js
...
|-Templates
|-index.html
I have install Parcel on resources dir and run:
parcel build public/js/index.js
However this generate files on dist dir.
How can I generate a single entry JS file containing all the JS using Parcel and keep the same structure of the application so I can continue using default path to link to this JS from index.html?
Source: (StackOverflow)
I've used auto generated feature of android plugin for android studio and it generated me the following code, but I can't understand why is there need for final val
for CREATOR
field ? I see final
keyword for the first time in kotlin.
data class Person(
val name: String,
val surname: String
) : Parcelable {
constructor(source: Parcel): this(source.readString(), source.readString())
override fun describeContents(): Int {
return 0
}
override fun writeToParcel(dest: Parcel?, flags: Int) {
dest?.writeString(name)
dest?.writeString(surname)
}
companion object {
@JvmField final val CREATOR: Parcelable.Creator<Person> = object : Parcelable.Creator<Person> {
override fun createFromParcel(source: Parcel): Person {
return Person(source)
}
override fun newArray(size: Int): Array<Person?> {
return arrayOfNulls(size)
}
}
}
}
Source: (StackOverflow)
if i change my host to a custom one, then i get the error above. This only happens in edge
I have tried to build other application in different techs to see if it was my language but its not
{
"name": "openlayers",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "parcel index.html --host development.landwebni.gov.uk --port 9095",
"build": "parcel build --public-url . index.html"
},
"author": "",
" license": "ISC",
"dependencies": {
"@babel/core": "^7.8.3",
"app-root-path": "^3.0.0",
"authenticate": "^0.1.5",
"babel-preset-es2015": "^6.24.1",
"babel-upgrade": "^1.0.1",
"commonjs": "0.0.1",
"config": "^3.2.5",
"core-js": "^3.6.4",
"document-ready": "^2.0.2",
"eazy-logger": "^3.0.2",
"fs": "0.0.1-security",
"jquery": "^3.4.1",
"leaflet": "^1.6.0",
"ol": "^6.1.1",
"ol-contextmenu": "^4.0.0",
"ol-hashed": "^2.0.0",
"ol-layerswitcher": "^3.5.0",
"proj4": "^2.6.0",
"sidebar-v2": "^0.4.0",
"simple-datatables": "^2.1.9",
"simple-node-logger": "^18.12.24",
"winston": "^3.2.1",
"winston-daily-rotate-file": "^4.4.1"
},
"devDependencies": {
"babel-preset-env": "^1.7.0",
"parcel-bundler": "^1.12.4"
},
" description": ""
}
Source: (StackOverflow)