Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(js): set moduleResolution to Node10 so it is compatible with CommonJS module #21979

Merged
merged 1 commit into from Feb 29, 2024

Conversation

jaysoo
Copy link
Member

@jaysoo jaysoo commented Feb 23, 2024

Since we set module to be CommonJS when transpiling .ts config files, it will fail if the workspace uses moduleResolution that is incompatible with CommonJS.

When you run any Nx command you'll get an error such as:

{
  stack: 'Error: Unable to create nodes for playwright.config.ts using plugin @nx/playwright/plugin. \n' +
    '\n' +
    '\t Inner Error: TSError: ⨯ Unable to compile TypeScript:\n' +
    "error TS5095: Option 'bundler' can only be used when 'module' is set to 'es2015' or later.\n" +
    '\n' +
    '    at createTSError (/Users/leosvel/code/playground/foo/node_modules/ts-node/src/index.ts:859:12)\n' +
    '    at reportTSError (/Users/leosvel/code/playground/foo/node_modules/ts-node/src/index.ts:863:19)\n' +
    '    at /Users/leosvel/code/playground/foo/node_modules/ts-node/src/index.ts:1379:34\n' +
    '    at Object.compile (/Users/leosvel/code/playground/foo/node_modules/ts-node/src/index.ts:1458:13)\n' +
    '    at Module.m._compile (/Users/leosvel/code/playground/foo/node_modules/ts-node/src/index.ts:1617:30)\n' +
    '    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)\n' +
    '    at Object.require.extensions.<computed> [as .ts] (/Users/leosvel/code/playground/foo/node_modules/ts-node/src/index.ts:1621:12)\n' +
    '    at Module.load (node:internal/modules/cjs/loader:1207:32)\n' +
    '    at Function.Module._load (node:internal/modules/cjs/loader:1023:12)\n' +
    '    at Module.require (node:internal/modules/cjs/loader:1235:19)\n' +
    '    at /Users/leosvel/code/playground/foo/node_modules/nx/src/project-graph/utils/project-configuration-utils.js:156:35\n' +
    '    at processTicksAndRejections (node:internal/process/task_queues:95:5)\n' +
    '    at async Promise.all (index 0)\n' +
    '    at async Promise.all (index 3)\n' +
    '    at async createProjectConfigurations (/Users/leosvel/code/playground/foo/node_modules/nx/src/project-graph/utils/retrieve-workspace-files.js:89:62)\n' +
    '    at async processFilesAndCreateAndSerializeProjectGraph (/Users/leosvel/code/playground/foo/node_modules/nx/src/daemon/server/project-graph-incremental-recomputation.js:140:28)\n' +
    '    at async getCachedSerializedProjectGraphPromise (/Users/leosvel/code/playground/foo/node_modules/nx/src/daemon/server/project-graph-incremental-recomputation.js:43:16)\n' +
    '    at async handleRequestProjectGraph (/Users/leosvel/code/playground/foo/node_modules/nx/src/daemon/server/handle-request-project-graph.js:12:24)\n' +
    '    at async handleResult (/Users/leosvel/code/playground/foo/node_modules/nx/src/daemon/server/server.js:110:16)\n' +
    '    at async handleMessage (/Users/leosvel/code/playground/foo/node_modules/nx/src/daemon/server/server.js:81:9)',
  message: 'Unable to create nodes for playwright.config.ts using plugin @nx/playwright/plugin. \n' +
    '\n' +
    '\t Inner Error: TSError: ⨯ Unable to compile TypeScript:\n' +
    "error TS5095: Option 'bundler' can only be used when 'module' is set to 'es2015' or later.\n" +
    '\n' +
    '    at createTSError (/Users/leosvel/code/playground/foo/node_modules/ts-node/src/index.ts:859:12)\n' +
    '    at reportTSError (/Users/leosvel/code/playground/foo/node_modules/ts-node/src/index.ts:863:19)\n' +
    '    at /Users/leosvel/code/playground/foo/node_modules/ts-node/src/index.ts:1379:34\n' +
    '    at Object.compile (/Users/leosvel/code/playground/foo/node_modules/ts-node/src/index.ts:1458:13)\n' +
    '    at Module.m._compile (/Users/leosvel/code/playground/foo/node_modules/ts-node/src/index.ts:1617:30)\n' +
    '    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)\n' +
    '    at Object.require.extensions.<computed> [as .ts] (/Users/leosvel/code/playground/foo/node_modules/ts-node/src/index.ts:1621:12)\n' +
    '    at Module.load (node:internal/modules/cjs/loader:1207:32)\n' +
    '    at Function.Module._load (node:internal/modules/cjs/loader:1023:12)\n' +
    '    at Module.require (node:internal/modules/cjs/loader:1235:19)\n' +
    '\n' +
    'Because of the error the Nx daemon process has exited. The next Nx command is going to restart the daemon process.\n' +
    'If the error persists, please run "nx reset".',
  cause: {
    stack: 'TSError: ⨯ Unable to compile TypeScript:\n' +
      "error TS5095: Option 'bundler' can only be used when 'module' is set to 'es2015' or later.\n" +
      '\n' +
      '    at createTSError (/Users/leosvel/code/playground/foo/node_modules/ts-node/src/index.ts:859:12)\n' +
      '    at reportTSError (/Users/leosvel/code/playground/foo/node_modules/ts-node/src/index.ts:863:19)\n' +
      '    at /Users/leosvel/code/playground/foo/node_modules/ts-node/src/index.ts:1379:34\n' +
      '    at Object.compile (/Users/leosvel/code/playground/foo/node_modules/ts-node/src/index.ts:1458:13)\n' +
      '    at Module.m._compile (/Users/leosvel/code/playground/foo/node_modules/ts-node/src/index.ts:1617:30)\n' +
      '    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)\n' +
      '    at Object.require.extensions.<computed> [as .ts] (/Users/leosvel/code/playground/foo/node_modules/ts-node/src/index.ts:1621:12)\n' +
      '    at Module.load (node:internal/modules/cjs/loader:1207:32)\n' +
      '    at Function.Module._load (node:internal/modules/cjs/loader:1023:12)\n' +
      '    at Module.require (node:internal/modules/cjs/loader:1235:19)',
    message: '⨯ Unable to compile TypeScript:\n' +
      "error TS5095: Option 'bundler' can only be used when 'module' is set to 'es2015' or later.\n"
  }
}

Current Behavior

Workspaces with moduleResolution: 'bundler' or esnext, etc. will error out when transpiling .ts config files like playwright.config.ts

Expected Behavior

.ts config files should work.

Related Issue(s)

Fixes #

@jaysoo jaysoo requested a review from a team as a code owner February 23, 2024 22:11
Copy link

vercel bot commented Feb 23, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Updated (UTC)
nx-dev ⬜️ Ignored (Inspect) Visit Preview Feb 29, 2024 3:07am

@jaysoo jaysoo changed the title fix(js): set moduleResolution to Node10 so it is compatible with Comm… fix(js): set moduleResolution to Node10 so it is compatible with CommonJS module Feb 23, 2024
@jaysoo jaysoo force-pushed the fix_ts_node_options branch 3 times, most recently from e4b5442 to 5a0f857 Compare February 26, 2024 14:29
@jaysoo jaysoo enabled auto-merge (squash) February 26, 2024 14:29
@jaysoo jaysoo force-pushed the fix_ts_node_options branch 5 times, most recently from cba1fac to 99f1e81 Compare February 28, 2024 22:59
@jaysoo jaysoo merged commit 56c34cf into master Feb 29, 2024
6 checks passed
@jaysoo jaysoo deleted the fix_ts_node_options branch February 29, 2024 04:08
Copy link

github-actions bot commented Mar 6, 2024

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants