# Fix "Cannot use import statement outside a module" in JavaScript

DevFeed: [Fix "Cannot use import statement outside a module" in JavaScript](<https://devfeed.tech/articles/fix-cannot-use-import-statement-outside-a-module-in-javascript-84525.md>)

Original publisher: [Read original article](<https://markodenic.com/cannot-use-import-statement-outside-a-module/>)

Author: Marko

Published: 2026-10-10T09:00:00Z

Content type: tutorial

Language: en

Sources: [Marko Denic Blog](<https://devfeed.tech/sources/marko-denic-blog.md>)

Topics: [import](<https://devfeed.tech/topics/import.md>), [CommonJS](<https://devfeed.tech/topics/commonjs.md>), [export](<https://devfeed.tech/topics/export.md>), [Node.js](<https://devfeed.tech/topics/node-js.md>), [TypeScript](<https://devfeed.tech/topics/typescript.md>), [Jest](<https://devfeed.tech/topics/jest.md>), [Webpack](<https://devfeed.tech/topics/webpack.md>)

Tags: [build](<https://devfeed.tech/tags/build.md>), [bundlers](<https://devfeed.tech/tags/bundlers.md>), [commonjs](<https://devfeed.tech/tags/commonjs.md>), [esm](<https://devfeed.tech/tags/esm.md>), [javascript](<https://devfeed.tech/tags/javascript.md>), [jest](<https://devfeed.tech/tags/jest.md>), [node-js](<https://devfeed.tech/tags/node-js.md>), [tutorial](<https://devfeed.tech/tags/tutorial.md>), [typescript](<https://devfeed.tech/tags/typescript.md>)

## AI overview

This tutorial explains why JavaScript reports "Cannot use import statement outside a module" and how to resolve it across browsers, Node.js, TypeScript, and Jest. It covers configuring ES modules, using file extensions or `require()`, and handling module system settings in TypeScript and test runners.

## Source excerpt

Why you get "SyntaxError: Cannot use import statement outside a module" and how to fix it in the browser, Node.js, TypeScript and Jest, with the exact change for each case.