Ask coding questions

← Back to all posts
'module' is not defined error for babel.config.js
EmilySeville7cf

Hello! I have the simple LinkedList<T> implementation written on TypeScript. The problem is in babel.config.js:

'module' is not defined error is shown in vscode for module. How to fix it? I am beginner in TypeScript.

More context

vscode

Version: 1.60.0
Commit: e7d7e9a9348e6a8cc8c03f877d39cb72e5dfb1ff
Date: 2021-09-01T10:43:02.136Z
Electron: 13.1.8
Chrome: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Linux x64 5.11.0-27-generic snap

node

Version: v14.17.4

Voters
EmilySeville7cf
Comments
hotnewtop
lightningrock

Firstly, try running it. It might just be VSCode, it sometimes shows errors that don't actually exist.

If you get an error in the console, then try to see if you have set up your JS files as ES6 modules. With ES6, instead of require("") and module.exports, you use import {} from "" and export;

So your config would become

The most obvious way is that you have set "type": "module" in your package.json.

EmilySeville7cf

@lightningrock, when I convert babel.config.js to ES6 module after npm run test I obtain error. But without conversion everything works fine inside the console.