Skip to content

Commit 0584ad7

Browse files
committed
Revert "fix: #22038 support esm import for windows (#22042)"
This reverts commit b83bdc2.
1 parent 309c31f commit 0584ad7

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

packages/launchpad/cypress/e2e/scaffold-project.cy.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,6 @@ function scaffoldAndOpenE2EProject (opts: {
4444
cy.contains('E2E Testing').click()
4545
cy.contains('We added the following files to your project:')
4646
cy.contains('Continue').click()
47-
// Going through the loading of config
48-
cy.get('[data-cy="loading-spinner"]')
49-
cy.get('[data-cy="loading-spinner"]').should('not.exist')
50-
// No errrors were encountered
51-
cy.get('[data-testid="error-header"]').should('not.exist')
52-
// Asserts that we've made it through the flow
53-
cy.contains('Choose a Browser')
5447
}
5548

5649
function scaffoldAndOpenCTProject (opts: {

packages/server/lib/plugins/child/run_require_async_child.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
require('graceful-fs').gracefulify(require('fs'))
22
const stripAnsi = require('strip-ansi')
33
const debug = require('debug')(`cypress:lifecycle:child:run_require_async_child:${process.pid}`)
4-
const { pathToFileURL } = require('url')
54
const tsNodeUtil = require('./ts_node')
65
const util = require('../util')
76
const { RunPlugins } = require('./run_plugins')
@@ -98,10 +97,12 @@ function run (ipc, file, projectRoot) {
9897
// 3a. Yes: Use bundleRequire
9998
// 3b. No: Continue through to `await import(configFile)`
10099
// 4. Use node's dynamic import to import the configFile
100+
let originalError
101101

102102
try {
103103
return require(file)
104104
} catch (err) {
105+
originalError = err
105106
if (!err.stack.includes('[ERR_REQUIRE_ESM]') && !err.stack.includes('SyntaxError: Cannot use import statement outside a module')) {
106107
throw err
107108
}
@@ -123,10 +124,16 @@ function run (ipc, file, projectRoot) {
123124
debug(`User doesn't have esbuild. Going to use native node imports.`)
124125

125126
// We cannot replace the initial `require` with `await import` because
126-
// Certain modules cannot be dynamically imported.
127-
128-
// pathToFileURL for windows interop: https://github.com/nodejs/node/issues/31710
129-
return await import(pathToFileURL(file).href)
127+
// Certain modules cannot be dynamically imported. If this throws, however, we want
128+
// to show the original error that was thrown, because that's ultimately the source of the problem
129+
try {
130+
return await import(file)
131+
} catch (e) {
132+
// If we aren't able to import the file at all, throw the original error, since that has more accurate information
133+
// of what failed to begin with
134+
debug('esbuild fallback for loading config failed, throwing original error. node import error: %o', e)
135+
throw originalError
136+
}
130137
}
131138

132139
throw err
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
exports['cypress config with esm and cjs / does not support modules and ts without esbuild in config-cjs-and-esm/config-with-ts-module'] = `
2+
STDOUT_ERROR_VALIDATED
3+
`

system-tests/test/config_modules_spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ describe('cypress config with esm and cjs', function () {
3232
spec: 'app.cy.js',
3333
browser: 'chrome',
3434
expectedExitCode: 1,
35+
snapshot: true,
36+
onStdout (stdout) {
37+
expect(stdout).to.include('nearest parent package.json contains "type": "module" which defines all .ts files in that package scope as ES modules')
38+
39+
// Need to make this stable b/c of filepaths, and snapshot: true is needed to invoke onStdout
40+
return 'STDOUT_ERROR_VALIDATED'
41+
},
3542
})
3643
})
3744

0 commit comments

Comments
 (0)