question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. Itย collects links to all the places you might be looking at while hunting down a tough bug.

And, if youโ€™re still stuck at the end, weโ€™re happy to hop on a call to see how we can help out.

Parcel API not working

See original GitHub issue

๐Ÿ› bug report

When I use the cli the project is building properly. But when I use Parcel API from @parcel/core no bundles are generated.

๐ŸŽ› Configuration (.babelrc, package.json, cli command)

Using default parcel config

{
  "name": "parcel-test",
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "start": "node server.js",
    "build": "parcel build index.html"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "react": "^17.0.2",
    "react-dom": "^17.0.2"
  },
  "devDependencies": {
    "@parcel/config-default": "^2.0.0",
    "parcel": "^2.0.0"
  }
}

๐Ÿค” Expected Behavior

Parcel should create assets in local filesystem.

๐Ÿ˜ฏ Current Behavior

No bundles are created. And bundle graph is empty object.

๐Ÿ’ Possible Solution

๐Ÿ”ฆ Context

๐Ÿ’ป Code Sample

const { default: Parcel } = require('@parcel/core');
const { NodeFS } = require('@parcel/fs');
const { join } = require('path');

const bundler = new Parcel({
    defaultConfig: "@parcel/config-default",
    entrypoints: [join(process.cwd(), 'index.html')],
    outputFS: new NodeFS()
});

bundler.run().then(console.log).catch(console.error);

See https://github.com/Devil7DK/Parcel-API-Test

๐ŸŒ Your Environment

Software Version(s)
Parcel 2.0.0
Node 14.17.3
npm/Yarn 6.14.13
Operating System Windows

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
HcroakerDevcommented, Nov 1, 2022

What I actually ended up doing to get this to work was to create two bundlers:

let webBundler = new Parcel({
  entries: ['client/index.html'],
  defaultConfig: '@parcel/config-default',
  targets: {
    client: {
      context: "browser",
      distDir: "dist/client"
    },
  },
  hmrOptions: {
    port: 3000,
  },
  defaultTargetOptions: {
    publicUrl: '/dist',
  }
});

let serverBundler = new Parcel({
  entries: ['server/main.js'],
  defaultConfig: '@parcel/config-default',
  targets: {
    server: {
      context: "node",
      outputFormat: "commonjs",
      distDir: "dist/server"
    },
  },
  defaultTargetOptions: {
    publicUrl: '/dist',
  }
});

That way I could have my server running and watching for changes and my client running with HMR enabled as well.

1reaction
Devil7DKcommented, Aug 7, 2022

Hi @Myrga

I have moved to a different bundler in that project due to this issue and another one.

Anyway, will try the solution you have given in my sample.

Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Diagnostics and Logging - Parcel
Parcel includes support for rich diagnostics that are used to describe errors and warnings in a format-agnostic way. It also includes a built...
Read more >
Issue when trying to start parcel development server
I installed it to my project using the npm install parcel command. Then I tried to start the development server by running the...
Read more >
Parcels API | single-spa
Most parcel methods will be called on the parcel itself, with the exception ... that returns a promise that resolves with the object...
Read more >
API Tech Support Guide - UPS
2017 United Parcel Service of America, Inc. All rights reserved. ... Code of Federal Regulations, Title 49 (49CFR) This API works in conjunction...
Read more >
How to Bundle a Web App with Parcel.js - DigitalOcean
You will be working interchangeably with a text editor and a terminal. ... files in this scenario are not meant to be edited...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found