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

[Solved] Cannot use import statement outside a module #51

Closed
jobwat opened this issue Feb 8, 2022 · 0 comments
Closed

[Solved] Cannot use import statement outside a module #51

jobwat opened this issue Feb 8, 2022 · 0 comments

Comments

@jobwat
Copy link

jobwat commented Feb 8, 2022

This is a typescript related issue.

The extension was failing on a new generated typescript project:

Jasmine Tests output:

(node:75786) UnhandledPromiseRejectionWarning: /private/tmp/test/spec/tests/users.spec.ts:1
import supertest from 'supertest';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (internal/modules/cjs/loader.js:988:16)
    at Module._compile (internal/modules/cjs/loader.js:1036:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
    at Module.load (internal/modules/cjs/loader.js:937:32)
    at Function.Module._load (internal/modules/cjs/loader.js:778:12)
    at Module.require (internal/modules/cjs/loader.js:961:19)
    at require (internal/modules/cjs/helpers.js:92:18)
    at Loader.requireShim [as require_] (/Users/yourmum/.vscode/extensions/hbenl.vscode-jasmine-test-adapter-1.7.1/node_modules/jasmine/lib/loader.js:35:3)
    at /Users/yourmum/.vscode/extensions/hbenl.vscode-jasmine-test-adapter-1.7.1/node_modules/jasmine/lib/loader.js:28:12
    at new Promise (<anonymous>)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:75786) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:75786) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

The fix has been found in another issue related to typescript:

Ensure ts-node and tsconfig-paths packages are installed and add this config to the settings.json of VScode

"jasmineExplorer.nodeArgv": [
        "--require",
        "ts-node/register",
        "--require",
        "tsconfig-paths/register"
    ],

Hope this helps the next one

$ node --version
v14.17.6
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

1 participant