Parcel: Empty bundle generated - transformer-typescript

Created on 22 Aug 2020  ยท  2Comments  ยท  Source: parcel-bundler/parcel

๐Ÿ› bug report

I am trying to bundle a simple Atom package using parcel and typescript-transformer. However, the resulting bundle is just an empty JavaScript file.

This is the console output using parcel@next

console: (node:53616) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 17 error listeners added to [WriteStream]. Use emitter.setMaxListeners() to increase limit
(Use `node --trace-warnings ...` to show where the warning was created)
console: (node:53616) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 17 close listeners added to [WriteStream]. Use emitter.setMaxListeners() to increase limit
โˆš Built in 4.90s

dist\main.js    34 B    734ms

Using the parcel@nightly a different error is thrown. (atom-package-deps is just a simple cjs package that is imported using dynamic import.)


ร— Build failed.
@parcel/packager-js: No reachable bundle found containing node_modulesatom-package-depslibindex.js
Error: No reachable bundle found containing node_modules\atom-package-deps\lib\index.js
    at addBundleImport (C:\Users\aminy\Documents\GitHub\JavaScript\@atom-ide-community\atom-ide-template\node_modules\@parcel\scope-hoisting\lib\link.js:346:13)
    at CallExpression (C:\Users\aminy\Documents\GitHub\JavaScript\@atom-ide-community\atom-ide-template\node_modules\@parcel\scope-hoisting\lib\link.js:437:20)
    at NodePath._call (C:\Users\aminy\Documents\GitHub\JavaScript\@atom-ide-community\atom-ide-template\node_modules\@babel\traverse\lib\path\context.js:55:20)
    at NodePath.call (C:\Users\aminy\Documents\GitHub\JavaScript\@atom-ide-community\atom-ide-template\node_modules\@babel\traverse\lib\path\context.js:42:17)
    at NodePath.visit (C:\Users\aminy\Documents\GitHub\JavaScript\@atom-ide-community\atom-ide-template\node_modules\@babel\traverse\lib\path\context.js:92:31)
    at TraversalContext.visitQueue (C:\Users\aminy\Documents\GitHub\JavaScript\@atom-ide-community\atom-ide-template\node_modules\@babel\traverse\lib\context.js:112:16)
    at TraversalContext.visitSingle (C:\Users\aminy\Documents\GitHub\JavaScript\@atom-ide-community\atom-ide-template\node_modules\@babel\traverse\lib\context.js:84:19)
    at TraversalContext.visit (C:\Users\aminy\Documents\GitHub\JavaScript\@atom-ide-community\atom-ide-template\node_modules\@babel\traverse\lib\context.js:140:19)
    at Function.traverse.node (C:\Users\aminy\Documents\GitHub\JavaScript\@atom-ide-community\atom-ide-template\node_modules\@babel\traverse\lib\index.js:82:17)
    at NodePath.visit (C:\Users\aminy\Documents\GitHub\JavaScript\@atom-ide-community\atom-ide-template\node_modules\@babel\traverse\lib\path\context.js:99:18)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `cross-env NODE_ENV=production parcel build --target main src/main.ts`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\aminy\AppData\Roaming\npm-cache\_logs\2020-08-22T08_56_35_181Z-debug.log

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

The full example is already uploaded here for you to try: https://github.com/atom-ide-community/atom-ide-template/tree/parcel


but if you prefer making your own project

.parcelrc

{
  "extends": "@parcel/config-default",
  "transformers": {
    "*.{ts,tsx}": ["@parcel/transformer-typescript-tsc"]
  }
}

package.json -> targets:

  "targets": {
    "main": {
      "context": "electron-renderer",
      "engines": {
        "electron": ">=5.x"
      },
      "includeNodeModules": {
        "atom": false,
        "electron": false,
        "coffee-script": false
      },
      "outputFormat": "commonjs",
      "isLibrary": true
    }
  },

build script:

    "build": "cross-env NODE_ENV=production parcel build --target main src/main.ts",

tsconfig

{
  "compilerOptions": {
    "strict": true,
    "strictNullChecks": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": true,
    "noImplicitAny": true,
    "noImplicitThis": true,
    "noFallthroughCasesInSwitch": true,
    "declaration": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "incremental": true,
    "inlineSourceMap": true,
    "inlineSources": true,
    "preserveSymlinks": true,
    "removeComments": true,
    "jsx": "react",
    "jsxFactory": "etch.dom",
    "lib": ["ES2018", "dom"],
    "target": "ES2018",
    "allowJs": true,
    "esModuleInterop": true,
    "module": "commonjs",
    "moduleResolution": "node",
    "importHelpers": false,
    "outDir": "../dist"
  },
  "compileOnSave": false
}

๐Ÿค” Expected Behavior

Bundle the package.

๐Ÿ˜ฏ Current Behavior

See the above bug-report description.

๐Ÿ’ Possible Solution

๐Ÿ”ฆ Context

๐Ÿ’ป Code Sample

https://github.com/atom-ide-community/atom-ide-template/tree/parcel

๐ŸŒ Your Environment

| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | ^2.0.0-beta.1 or 2.0.0-nightly.377
| @parcel/transformer-typescript-tsc | ^2.0.0-beta.1 or 2.0.0-nightly.379
| Node | 14.8.0
| npm/Yarn | 6.14.7
| Operating System | Win 10

Bug โœจ Parcel 2

Most helpful comment

I've just opened a PR: https://github.com/parcel-bundler/parcel/pull/5053. It's not really related to scope hoisting.

You can also try this already by adding these changes to your .parcelrc: https://github.com/parcel-bundler/parcel/pull/5053/files#diff-89039bac63e920d9ab1ea1bdf8d794ba (so adding a runtime: key with these two electron lines)

All 2 comments

Building with --no-scope-hoist solves the issue! I think this is an edge case in which scope hoisting does not work.

cc: @mischnic @DeMoorJasper

I've just opened a PR: https://github.com/parcel-bundler/parcel/pull/5053. It's not really related to scope hoisting.

You can also try this already by adding these changes to your .parcelrc: https://github.com/parcel-bundler/parcel/pull/5053/files#diff-89039bac63e920d9ab1ea1bdf8d794ba (so adding a runtime: key with these two electron lines)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

davidnagli picture davidnagli  ยท  3Comments

philipodev picture philipodev  ยท  3Comments

algebraic-brain picture algebraic-brain  ยท  3Comments

humphd picture humphd  ยท  3Comments

dotdash picture dotdash  ยท  3Comments