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

Cannot use import statement outside a module in .spec.ts files in unit test. #102

Closed
lprintf opened this issue Sep 16, 2021 · 3 comments
Closed

Comments

@lprintf
Copy link
Contributor

lprintf commented Sep 16, 2021

After update tsconfig to 0.20.2 in PR #97 encounter a problem about unit test.

logs:detail

> [email protected] test:unit
> blue-tape -r ts-node/register 'src/**/*.spec.ts' 'tests/**/*.spec.ts'

/workspace/src/appservice-manager.spec.ts:2
import { test } from 'tstest';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1031:15)
    at Module._compile (node:internal/modules/cjs/loader:1065:27)
    at Module.m._compile (/workspace/node_modules/ts-node/src/index.ts:1310:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Object.require.extensions.<computed> [as .ts] (/workspace/node_modules/ts-node/src/index.ts:1313:12)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:94:18)
@lprintf
Copy link
Contributor Author

lprintf commented Sep 16, 2021

It work well in @chatie/tsconfig 0.16.2. Should we give up upgrading the dependency? @huan

@huan
Copy link
Member

huan commented Sep 16, 2021

Please refer to Chatie/tsconfig#16 to see how to make the repo work with the esm.

In short:

  1. You need to add "type": "module" to package.json
  2. You need to use import './config.js' instead of import './config'
  3. Rename .eslint.js to .eslint.cjs

@lprintf
Copy link
Contributor Author

lprintf commented Sep 24, 2021

fix in #97

@lprintf lprintf closed this as completed Sep 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants