js-lingui icon indicating copy to clipboard operation
js-lingui copied to clipboard

Importing macro in workspace project shows that the export variable is not defined

Open jzsn2018 opened this issue 2 years ago • 1 comments

Describe the bug image image

To Reproduce

// Project directory
packages
├── README.md
├── grafana-data
├── grafana-e2e
├── grafana-e2e-selectors
├── grafana-runtime
├── grafana-schema
├── grafana-toolkit
├── grafana-ui
├── jaeger-ui-components
└── grafana-i18n <--- 
// code in packages/grafana-i18n/src/index.ts

import { i18n } from "@lingui/core"
import { t } from "@lingui/macro"
console.log("i18n", i18n); // print ok
console.log("t", t); //  Uncaught ReferenceError: t is not defined

// packages/grafana-i18n/package.json
{
  "name": "@grafana-i18n",
  "packageManager": "[email protected]",
  "main": "src/index.ts",
  "dependencies": {
    "@lingui/core": "3.13.3",
    "@lingui/macro": "3.13.3",
    "@lingui/react": "3.13.3"
  },
  "devDependencies": {
    "@types/lingui__macro": "^3",
    "babel-plugin-macros": "3.1.0"
  }
}

// packages/grafana-i18n/tsconfig.json
{
  "compilerOptions": {
    "declarationDir": "dist",
    "target": "es2016",
    "outDir": "compiled",
    "rootDirs": ["."],
    "paths": {
      "@grafana/i18n": ["."]
    }
  },
  "exclude": ["dist", "node_modules"],
  "extends": "@grafana/tsconfig",
  "include": ["src/**/*.ts*"]
}

Expected behavior print t is ok

Additional context Add any other context about the problem here.

  • jsLingui version 3.13.3
  • Babel version 7.17.8
  • Your Babel config (e.g. .babelrc) or framework you use (Create React App, Meteor, etc.)
// babel.config.json
{
  "babelrc": false,
  // Note: order is bottom-to-top and/or right-to-left
  "presets": [
    [
      "@babel/preset-env",
      {
        "bugfixes": true,
        "browserslistEnv": "dev",
        "useBuiltIns": "entry",
        "corejs": "3.10"
      }
    ],
    [
      "@babel/preset-typescript",
      {
        "allowNamespaces": true,
        "allowDeclareFields": true
      }
    ],
    [
      "@babel/preset-react",
      {
        "runtime": "automatic"
      }
    ]
  ],
  "plugins": [
    [
      "@babel/plugin-transform-typescript",
      {
        "allowNamespaces": true,
        "allowDeclareFields": true
      }
    ],
    // added to mitigate https://github.com/babel/babel/issues/14289
    // package (and following line) can be removed once the issue is fixed and released
    "@babel/plugin-proposal-class-properties",
    ["@babel/plugin-proposal-object-rest-spread", { "loose": true }],
    "@babel/plugin-transform-react-constant-elements",
    "@babel/plugin-proposal-nullish-coalescing-operator",
    "@babel/plugin-proposal-optional-chaining",
    "@babel/plugin-syntax-dynamic-import", // needed for `() => import()` in routes.ts
    "angularjs-annotate",
    "macros"
  ],
  "env": {
    "production": {
      "presets": [
        [
          "@babel/preset-env",
          {
            "browserslistEnv": "production"
          }
        ]
      ]
    },
    "hot": {
      "plugins": ["react-refresh/babel"]
    }
  }
}

jzsn2018 avatar Jun 26 '22 15:06 jzsn2018

I believe it needs to be wrapped in a provider

timtyrrell avatar Aug 22 '22 19:08 timtyrrell

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Oct 22 '22 16:10 stale[bot]