@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:
- Created 4 years ago
- Comments:8 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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
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.