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

Support spack.config.cjs #3345

Open
theoparis opened this issue Jan 24, 2022 · 2 comments
Open

Support spack.config.cjs #3345

theoparis opened this issue Jan 24, 2022 · 2 comments
Labels

Comments

@theoparis
Copy link

Describe the bug

I put "type": "module" in my package.json, and tried to use spack but it gives the first error message.

If I specify the --config option with spack it gives the second error message.

Error messages

1st error:

spack.config.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead rename spack.config.js to end in .cjs, 
change the requiring code to use dynamic import() which is available in all CommonJS modules, 
or change "type": "module" to "type": "commonjs" in
 /mnt/data/projects/elemental-loader/pkg/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

2nd error:

/mnt/data/projects/elemental-loader/pkg/node_modules/.pnpm/@swc+core@1.2.133/node_modules/@swc/core/spack.js:55
                throw new Error(`Error occurred while loading config file at ${config}: ${e}`);
                      ^

Error: Error occurred while loading config file at spack.config.cjs: Error: Cannot find module 'spack.config.cjs'
Require stack:
- /mnt/data/projects/elemental-loader/pkg/node_modules/.pnpm/@swc+core@1.2.133/node_modules/@swc/core/spack.js

Input code

Multiple typescript files

Config

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "dynamicImport": true,
      "functionBind": false,
      "decorators": true,
      "topLevelAwait": true,
      "importMeta": true
    },
    "target": "es5",
    "loose": false
  },
  "module": {
    "type": "es6",
    "strict": false,
    "strictMode": true,
    "lazy": false,
    "noInterop": false
  }
}

Playground link

No response

Expected behavior

The configuration file to be parsed and a bundled js file to be produced.

Actual behavior

Gives errors about spack config file having the .cjs extension even with the --config flag.

Version

1.2.133

Additional context

No response

@kwonoj
Copy link
Member

kwonoj commented Jan 24, 2022

This is due to we don't have full native esm support yet. #3097 (comment)

@russelldavis
Copy link

The second error is because swc requires an absolute path when specifying a file with --config. As a workaround, you can do something like spack foo.ts --config "$PWD/spack.config.cjs"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants