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.

Tree shaking with TS throw `token.ts does not export 'Token'`

See original GitHub issue

🐛 bug report

Parcel says Token, which is a typescript interface, is not exported when I use --experimental-scope-hoisting.

I create a repo to reproduce this issue.

🎛 Configuration (.babelrc, package.json, cli command)

>>> git clone https://github.com/ocavue/parcel_issue_3153.git
>>> cd parcel_issue_3153
>>> yarn install
✨  Done in 0.38s.

>>> yarn run build1
yarn run v1.16.0
$ parcel build index.html
✨  Built in 45ms.

dist/tmp_parcel_issue.a55b6250.js        1.71 KB    9ms
dist/tmp_parcel_issue.a55b6250.js.map    1.03 KB    3ms
dist/index.html                            304 B    5ms
✨  Done in 0.74s.

>>> yarn run build2                                                                                                                               
yarn run v1.16.0
$ parcel build index.html --experimental-scope-hoisting
🚨  pkg/token.ts does not export 'Token'
    at replaceExportNode (/tmp/parcel_issue/node_modules/parcel-bundler/src/scope-hoisting/concat.js:54:13)
    at ReferencedIdentifier (/tmp/parcel_issue/node_modules/parcel-bundler/src/scope-hoisting/concat.js:317:20)
    at newFn (/tmp/parcel_issue/node_modules/parcel-bundler/node_modules/@babel/traverse/lib/visitors.js:230:17)
    at NodePath._call (/tmp/parcel_issue/node_modules/parcel-bundler/node_modules/@babel/traverse/lib/path/context.js:53:20)
    at NodePath.call (/tmp/parcel_issue/node_modules/parcel-bundler/node_modules/@babel/traverse/lib/path/context.js:40:17)
    at NodePath.visit (/tmp/parcel_issue/node_modules/parcel-bundler/node_modules/@babel/traverse/lib/path/context.js:88:12)
    at TraversalContext.visitQueue (/tmp/parcel_issue/node_modules/parcel-bundler/node_modules/@babel/traverse/lib/context.js:118:16)
    at TraversalContext.visitSingle (/tmp/parcel_issue/node_modules/parcel-bundler/node_modules/@babel/traverse/lib/context.js:90:19)
    at TraversalContext.visit (/tmp/parcel_issue/node_modules/parcel-bundler/node_modules/@babel/traverse/lib/context.js:146:19)
    at Function.traverse.node (/tmp/parcel_issue/node_modules/parcel-bundler/node_modules/@babel/traverse/lib/index.js:94:17)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

🤔 Expected Behavior

yarn run build2 should work

😯 Current Behavior

yarn run build2 doesn’t work

💁 Possible Solution

🔦 Context

Maybe it’s a duplicate of #2837. But this issue involves TS so I’m not sure.

💻 Code Sample

N/A

🌍 Your Environment

Software Version(s)
Parcel 1.12.3
Node 12.4.0
npm/Yarn yarn 1.16.0
Operating System macOS 10.13

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ocavuecommented, Jun 23, 2019

Thank you so much for your comments. I have found a solution after reading the docs you quoted.

<<<<<<<<<<<<<<<<<<<<<<<<pkg/main.ts>>>>>>>>>>>>>>>>>>>>>
import { Token } from './token'
export type Token = Token
export { func } from "./func"

BTW, a related issue can be found here: https://github.com/babel/babel/issues/8361

0reactions
ocavuecommented, Jan 17, 2020

Since it’s actually a Babel issue instead of a parcel issue, I close it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack5 does not seem to tree-shake unused exports
I tried changing all files to .js and removing the whole ts-loader thing. Tree-shaking now work as intented. The updated question now is...
Read more >
Firebase JavaScript SDK Release Notes - Google
Prevent the SDK from throwing errors if it is unable to log platform data due to an IndexedDB error. It will log a...
Read more >
Documentation - Ethers.js
A Provider (in ethers) is a class which provides an abstraction for a connection to the Ethereum Network. It provides read-only access to...
Read more >
Module Constraints - Remix
Browser-only code - Remix renders on the server so your modules can't have module ... Consider a route module that exports loader ,...
Read more >
TypeScript Jest: Unexpected Token Export - Reddit
Ok so now your test project is using common JS, but node sees your dependency as an ES Module, so it throws an...
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