Skip to content

Commit

Permalink
fix: Fix useESModules error warning.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Feb 25, 2021
1 parent b209b50 commit e52f77a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/tsbb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"jest": "26.6.3",
"ora": "5.1.0",
"typescript": "4.1.3",
"semver": "7.3.4",
"yargs": "16.1.1"
},
"devDependencies": {
Expand Down
4 changes: 3 additions & 1 deletion packages/tsbb/src/babel/transform.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from 'path';
import semver from 'semver';
import { transformFile, BabelFileResult, TransformOptions, loadOptions } from '@babel/core';
import { IOptions } from '@tsbb/babel-preset-tsbb';

Expand Down Expand Up @@ -29,12 +30,13 @@ export default (filePath: string, options: ITransformOptions, targets: ITargets)
} as any;
}
if (options.envName === 'esm') {
const runtimeVersion = semver.clean(require('@babel/runtime/package.json').version);
presetOptions.modules = false;
presetOptions.transformRuntime = {
// [@babel/plugin-transform-runtime] The 'useESModules' option is not necessary when using
// a @babel/runtime version >= 7.13.0 and not using the 'absoluteRuntime' option,
// because it automatically detects the necessary module format.
useESModules: true,
useESModules: !semver.gte(runtimeVersion, '7.13.0'),
version: require('@babel/helpers/package.json').version,
} as any;
}
Expand Down

0 comments on commit e52f77a

Please sign in to comment.