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/ts-utils does not work on node without es module support

See original GitHub issue

๐Ÿ› bug report

@parcel/ts-utils does not work on node without es module support.

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

.parcelrc

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

๐Ÿค” Expected Behavior

The project compiles successfully.

๐Ÿ˜ฏ Current Behavior

Node emits an error in script of @parcel/ts-utils.

๐Ÿ’ Possible Solution

Emit code with commonjs modules on package @parcel/ts-utils.

๐Ÿ”ฆ Context

Node emits the following error:

 Error: Unexpected token 'export'
~/node_modules/@parcel/ts-utils/src/index.js:2
export * from './FSHost';
^^^^^^

SyntaxError: Unexpected token 'export'
    at wrapSafe (internal/modules/cjs/loader.js:1043:16)
    at Module._compile (internal/modules/cjs/loader.js:1091:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1160:10)
    at Module.load (internal/modules/cjs/loader.js:976:32)
    at NodePackageManager.load (~/node_modules/@parcel/package-manager/lib/NodePackageManager.js:106:9)
    at NodePackageManager.requireSync (~/node_modules/@parcel/package-manager/lib/NodePackageManager.js:72:17)
    at Module.m.require (~/node_modules/@parcel/package-manager/lib/NodePackageManager.js:93:19)
    at require (internal/modules/cjs/helpers.js:69:18)
    at Object.<anonymous> (~/node_modules/@parcel/transformer-typescript-tsc/lib/TSCTransformer.js:10:16)
    at Module._compile (internal/modules/cjs/loader.js:1121:30)

tsconfig.json

{
  "compilerOptions": {
    "incremental": true,
    "target": "es5",
    "module": "commonjs",
    "jsx": "react",
    "rootDir": "./src",

    "strict": true,

    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,

    "esModuleInterop": true,

    "forceConsistentCasingInFileNames": true,

    "baseUrl": "./src",
    "paths": {
      "~*": ["./*"]
    }
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules"]
}

๐Ÿ’ป Code Sample

https://github.com/xfoxfu/parcel-issue-3931

๐ŸŒ Your Environment

Software Version(s)
Parcel 2.0.0-alpha.3.2
Node 13.4.0
npm/Yarn 1.19.2
Operating System macOS 10.15.2

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
saint-justincommented, Aug 17, 2021

Ok the problem was that it used alpha version of the @parcel/transformer-typescript-tsc package instead of ^2.0.0-beta.3.1. Just leaving it here if someone have similar problem.

Had the same issue as @lukejagodzinski, the command below solved the problem for me too for anyone else running into this. Make sure this is the right version for you if youโ€™re a person from the future.

npm i --save-dev @parcel/transformer-typescript-tsc@^2.0.0-beta.3.1

2reactions
lukejagodzinskicommented, Jun 20, 2021

Ok the problem was that it used alpha version of the @parcel/transformer-typescript-tsc package instead of ^2.0.0-beta.3.1. Just leaving it here if someone have similar problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using ES modules in Node.js - LogRocket Blog
In this article, we are going to learn about ES modules in Node. ... Currently, this is no longer required as from version...
Read more >
Error [ERR_REQUIRE_ESM]: require() of ES Module not ...
The node-fetch latest version doesn't use the require() syntax to import the package. You need to go to your package.json and type
Read more >
ECMAScript modules | Node.js v19.3.0 Documentation
Modules are defined using a variety of import and export statements. The following example of an ES module exports a function:
Read more >
Node Modules at War: Why CommonJS and ES ... - Code Red
Here's a CJS example where util.cjs sets a default export. The default export has no name; modules using require() define their own name....
Read more >
Documentation - ECMAScript Modules in Node.js - TypeScript
mjs files are always ES modules, and .cjs files are always CommonJS modules, and there's no way to override these. In turn, TypeScript...
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