这是indexloc提供的服务,不要输入任何密码
Skip to content

Cannot Build files on Windows with absolute, or relative paths #1150

@0xSero

Description

@0xSero

Our goal:

  • We are taking 2 .ts files and building them with tsup
  • We output the build in another directory for later use
  • This process is working flawlessly on Unix based OS (Mac, Linux, WSL)
  • We would like to expand our library to support users running Windows

Problem:

  • Once files are located via Glob, we verify their existence with fs.existsSync() which return true
  • We then pass an array of the file paths to build as seen below:
export async function compileWalletSetupFunctions(
  walletSetupDir: string,
  debug: boolean
) {
  const outDir = path.join(ensureCacheDirExists(), OUT_DIR_NAME);

  // Use a normalized glob pattern
  const globPattern = path.join(walletSetupDir, '**', '*.setup.{ts,js,mjs}');
  
  // Use glob to find files, ensuring proper path handling
  const fileList = await glob(globPattern, { absolute: true, windowsPathsNoEscape: true });

  if (debug) {
    console.log('[DEBUG] Found the following wallet setup files:');
    console.log(fileList, '\n');
  }

  // TODO: This error message is copied over from another function. Refactor this.
  if (!fileList.length) {
    throw new Error(
      [
        `No wallet setup files found at ${walletSetupDir}`,
        'Remember that all wallet setup files must end with `.setup.{ts,js,mjs}` extension!'
      ].join('\n')
    );
  }

  try {
    await build({
      name: 'cli-build',
      silent: true,
      entry: fileList,
      clean: true,
      outDir,
      format: 'esm',
      splitting: true,
      sourcemap: false,
      config: false,
      // TODO: Make this list configurable.
      external: ['@synthetixio/synpress', '@playwright/test', 'playwright-core', 'esbuild', 'tsup'],
      banner: {
        js: FIXES_BANNER
      },
      esbuildOptions(options) {
        // TODO: In this step, if the debug file is present, we should modify `console.log` so it prints from which file the log is coming from.
        // We're dropping `console.log` and `debugger` statements because they do not play nicely with the Playwright Test Runner.
        options.drop = debug ? [] : ['console', 'debugger']
      }
    })
  } catch (e) {
    console.log(e)
  }
  return outDir
}
  • An error occurs at ts normalizeOptions():
    error Error within compile PrettyError file: Cannot find C:\Users\**\**\**\reponame\filepath\filename.ts
  • I've tried to convert to url and passed file:\\C:\Users\**\**\**\reponame\filepath\filename.ts and there I'd get another issue:
    ERR_UNSUPPORTED_ESM_URL_SCHEME
  • I've also tried non absolute paths, with no luck.

At my whits end as I've read most of the issues in the repo, maybe I'm missing something super obvious but any help would be appreciated.

Resources:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions