question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Type error: Cannot compile namespaces when the '--isolatedModules' flag is provided.

See original GitHub issue

Describe the bug I’m trying to get started with js-lingui.

/src/locales/de/messages.js
Type error: Cannot compile namespaces when the '--isolatedModules' flag is provided.  TS1208

  > 1 | /* eslint-disable */module.exports={languageData:{"plurals":function(n,ord){var s=String(n).split("."),v0=!s[1];if(ord)return"other";return n==1&&v0?"one":"other"}},messages:{"description":"Beschreibung"}};
      |                     ^

To Reproduce Steps to reproduce the behavior, possibly with minimal code sample, e.g:

import * as React from 'react';
import { I18nProvider } from '@lingui/react';
import { Header } from './Header';

import catalogDe from '../locales/de/messages.js';
import catalogEn from '../locales/en/messages.js';

const catalogs = {
  de: catalogDe,
  en: catalogEn,
};

export const App = () => (
  <I18nProvider language="en" catalogs={catalogs}>
      <Header /> 
  </I18nProvider>
);

export default App;

Expected behavior Should compile

Additional context Using create-react-app, newest version where they introduces typescript support

{
    "@babel/core": "7.1.2",
    "@lingui/react": "2.7.0",
    "@lingui/cli": "2.7.0",
    "@lingui/macro": "2.7.0",
    "@types/lingui__core": "2.1.1",
    "@types/lingui__macro": "2.7.0",
    "@types/lingui__react": "2.5.0",
    "babel-core": "7.0.0-bridge.0",
    "react-scripts": "2.1.0",
    "typescript": "3.1.4"
}

tsconfig.json

create-react-app needs isolatedModules set to true.

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["es6", "dom"],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "preserve",
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noImplicitAny": true,
    "importHelpers": true,
    "strictNullChecks": true,
    "suppressImplicitAnyIndexErrors": true,
    "noUnusedLocals": true
  },
  "exclude": [
    "node_modules",
    "build",
    "scripts",
    "acceptance-tests",
    "webpack",
    "jest",
    "src/setupTests.ts"
  ],
  "include": ["src"]
}

This issue could be related, although it is about json: https://github.com/Microsoft/TypeScript/pull/28207

I guess I’ve a mistake in usage or configuration or it’s a beginner mistake. I appreciate the help. Thanks in advance.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
tricoder42commented, Oct 30, 2018

Hey @andys8, I honestly don’t know anything about Typescript, but you could also try set compileNamespace to es if it helps:

https://lingui.js.org/ref/conf.html#compilenamespace

0reactions
andys8commented, Oct 30, 2018

Created PR #378. Created another (minor) one for the same chapter before (https://github.com/lingui/js-lingui/pull/376), when you’re already looking at it 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot compile namespaces when the '--isolatedModules ...
When I add an empty main.ts in server folder, it always shows: Cannot compile namespaces when the '--isolatedModules' flag is provided. Even I ......
Read more >
"Cannot compile namespaces" error with --isolatedModules ...
src/a.ts(1,1): error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. This occurs because we in program.ts ...
Read more >
create-react-app --typescript: Cannot compile namespaces ...
Coding example for the question create-react-app --typescript: Cannot compile namespaces when the '--isolatedModules' flag is provided-Reactjs.
Read more >
Reactjs – create-react-app –typescript: Cannot compile namespaces ...
There is an error: Cannot compile namespaces when the '--isolatedModules' flag is provided. enter image description here. What should I do?
Read more >
isolatedModules - TSConfig Option - TypeScript
Setting the isolatedModules flag tells TypeScript to warn you if you write certain code that can't be correctly interpreted by a single-file transpilation ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found