Categories
Mastering Development

error TS1259: Module ‘”./node_modules/@types/express/index”‘ can only be default-imported using the ‘esModuleInterop’ flag

I’m trying to import express into the project and in the middle of the development, it just stopped working, i’ve reseted configurations, etc. Can’t make it work, can’t import any modules. npx tsc src/server.ts src/server.ts:1:8 – error TS1259: Module ‘"/home/fpc-ubut/Git/nlw2/server/node_modules/@types/express/index"’ can only be default-imported using the ‘esModuleInterop’ flag 1 import express from ‘express’; src/database/migrations/00_create_users.ts:1:8 – […]

Categories
Mastering Development

TypeScript not finding variable declared in type declaration if I import a file

I made a very simple library which contains a .d.ts (source) which has the following structure (I omit the details because the file works fine, it likely is a config issue in my project): // Some helper types and interfaces type TranslationFunction = /* … */; export { TranslationFunction }; Then, I do npm i […]

Categories
Mastering Development

TypeScript project in NPM not a constructor

I have an npm module built with TypeScript.. and I cannot seem to require() the module in other code MyClass4TS myclass4ts.ts class MyClass4TS { constructor(){ } } export { MyClass4TS } edit: Also tried attaching export to the class, to no effect export default class MyClass4TS { constructor(){ } } MyClass4TS package.json { “name”: “myclass4ts”, […]

Categories
Development

How to attach to nodemon process with WebStorm and TypeScript setting

I use debugger “attach to node.js/chrome”. My WebStorm debugger configuration. Host: localhost port: 9229 attach to: Chrome or node.js > 6.3 started with –inspect I am using TypeScript. My tsconfig.json file. { “compilerOptions”: { /* Basic Options */ “target”: “es6”, /* Specify ECMAScript target version: ‘ES3’ (default), ‘ES5’, ‘ES2015’, ‘ES2016’, ‘ES2017’, ‘ES2018’, ‘ES2019’ or ‘ESNEXT’. […]

Categories
Development

React Native with typescript unable to resolve modules

This is embarrassing, but I don’t know what else to do. I wanted to port my little React Native project to TypeScript, so I created an empty React Native project with TypeScript template, tweaked tsconfig.json to use custom paths such as @app and I tried to run it. It didn’t. And this was yesterday, I […]

Categories
Development

Adding tsconfig exclude causes “Cannot write file” errors?

If I add this exclude block to my tsconfig.json file: “exclude”: [“angular-package-format-workspace”] The following errors appear in VSCode. They disappear if I remove the exclude block (Also the exclude block has the desired affect – so just curious why VSCode is painting the errors): SON schema for the TypeScript compiler’s configuration file Cannot write file […]

Categories
Development

Jest & React & Typescript & React-Testing-Library error

I have a React/NextJS project setup using Typescript and am adding unit testing with Jest and React Testing Library. A unit test for my component looks like this: import React from ‘react’; import ‘@testing-library/jest-dom/extend-expect’; import { render } from ‘@testing-library/react’; import AppLayout from ‘.’; describe(‘<AppLayout>’, () => { it(‘renders children’, () => { const children […]

Categories
Development

Why create-react-app alias is not able to find index.js from folder?

I am stuck up with a weird issue while creating alias for my app. I am trying to create the alias adding jsconfig.json what looks like { “compilerOptions”: { “lib”: [ “dom”, “es2015”, “es2016”, “es6”, “es2017” ], “target”: “es2017”, “module”: “es6”, “allowSyntheticDefaultImports”: true, “baseUrl”: “./”, “paths”: { “actions/*”: [“src/actions/*”], “public/*”: [“public/*”], “components/*”: [“src/components/*”], “containers/*”: [“src/containers/*”], […]