Skip to content

Commit

Permalink
Fix #1235
Browse files Browse the repository at this point in the history
  • Loading branch information
cspotcode committed Feb 22, 2021
1 parent 5f809d1 commit 66b2603
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,16 @@ export { createRepl, CreateReplOptions, ReplService } from './repl'
*/
const engineSupportsPackageTypeField = parseInt(process.versions.node.split('.')[0], 10) >= 12

// Loaded conditionally so we don't need to support older node versions
let assertScriptCanLoadAsCJSImpl: ((filename: string) => void) | undefined

/**
* Assert that script can be loaded as CommonJS when we attempt to require it.
* If it should be loaded as ESM, throw ERR_REQUIRE_ESM like node does.
*
* Loaded conditionally so we don't need to support older node versions
*/
function assertScriptCanLoadAsCJS (filename: string) {
if (!engineSupportsPackageTypeField) return
if (!assertScriptCanLoadAsCJSImpl) assertScriptCanLoadAsCJSImpl = require('../dist-raw/node-cjs-loader-utils').assertScriptCanLoadAsCJSImpl
assertScriptCanLoadAsCJSImpl!(filename)
}
const assertScriptCanLoadAsCJS: (filename: string) => void =
engineSupportsPackageTypeField
? require('../dist-raw/node-cjs-loader-utils').assertScriptCanLoadAsCJSImpl
: () => {/* noop */}

/**
* Registered `ts-node` instance information.
Expand Down

0 comments on commit 66b2603

Please sign in to comment.