webpack-contrib / i18n-webpack-plugin

[DEPRECATED] Embed localization into your bundle
MIT License
317 stars 74 forks source link

Typescript cant find name '___' #63

Closed hallgren closed 6 years ago

hallgren commented 7 years ago

When I use typescript in the combination with i18n-webpack-plugin I get the following Error:

error TS2304: Cannot find name '___'.

It seams to me that the '__' function is not replaced with the translation before the execution of the ts-loader.

Link to test project

My Setup

Windows 10 pro version 1703 node 6.11.2 npm 3.10.10

webpack@3.6.0 ts-loader@2.3.7 / awesome-typescript-loader@3.2.3 i18n-webpack-plugin@1.0.0

Stacktrace

The output when npm run start on the test project.

PS F:\morgan\typeScriptin18nConfig> npm run start

> fa-multibanco@1.0.0 start F:\morgan\typeScriptin18nConfig
> webpack-dev-server --open

clean-webpack-plugin: F:\morgan\typeScriptin18nConfig\dist has been removed.
Project is running at http://localhost:8080/
webpack output is served from /
Content not from webpack is served from F:\morgan\typeScriptin18nConfig\dist
ts-loader: Using typescript@2.5.2 and F:\morgan\typeScriptin18nConfig\tsconfig.json
ts-loader: Using typescript@2.5.2 and F:\morgan\typeScriptin18nConfig\tsconfig.json
webpack: wait until bundle finished: /
Hash: 054e368d8a35a9ec7e7cf6f351c324c767f36e0bdfaf739f3315f55626b4
Version: webpack 3.6.0
Child
    Hash: 054e368d8a35a9ec7e7c
    Time: 3477ms
              Asset       Size  Chunks                    Chunk Names
     main.bundle.js     307 kB       0  [emitted]  [big]  main
    ../css/main.css   32 bytes       0  [emitted]         main
      ../index.html  342 bytes          [emitted]
      [33] multi (webpack)-dev-server/client?http://localhost:8080 ./src/index.tsx 40 bytes {0} [built]
      [34] (webpack)-dev-server/client?http://localhost:8080 7.27 kB {0} [built]
      [35] ./node_modules/url/url.js 23.3 kB {0} [built]
      [41] ./node_modules/strip-ansi/index.js 161 bytes {0} [built]
      [42] ./node_modules/ansi-regex/index.js 135 bytes {0} [built]
      [43] ./node_modules/loglevel/lib/loglevel.js 7.74 kB {0} [built]
      [44] (webpack)-dev-server/client/socket.js 1.04 kB {0} [built]
      [45] ./node_modules/sockjs-client/lib/entry.js 244 bytes {0} [built]
      [74] (webpack)-dev-server/client/overlay.js 3.71 kB {0} [built]
      [79] (webpack)/hot nonrecursive ^\.\/log$ 170 bytes {0} [built]
      [80] (webpack)/hot/log.js 1.04 kB {0} [optional] [built]
      [81] (webpack)/hot/emitter.js 77 bytes {0} [built]
      [82] ./node_modules/events/events.js 8.33 kB {0} [built]
      [83] ./src/index.tsx 91 bytes {0} [built]
      [84] ./src/scss/main.scss 41 bytes {0} [built]
        + 71 hidden modules
    Child html-webpack-plugin for "..\index.html":
         1 asset
           [0] ./node_modules/html-webpack-plugin/lib/loader.js!./src/template.html 607 bytes {0} [built]
           [1] ./node_modules/lodash/lodash.js 540 kB {0} [built]
           [2] (webpack)/buildin/global.js 509 bytes {0} [built]
           [3] (webpack)/buildin/module.js 517 bytes {0} [built]
    Child extract-text-webpack-plugin node_modules/extract-text-webpack-plugin/dist node_modules/css-loader/index.js!node_modules/sass-loader/lib/loader.js??ref--0-2!src/scss/main.scss:
           [0] ./node_modules/css-loader!./node_modules/sass-loader/lib/loader.js?{"includePaths":["./src/scss"]}!./src/scss/main.scss 200 bytes {0} [built]
           [1] ./node_modules/css-loader/lib/css-base.js 2.26 kB {0} [built]
Child ec:
    Hash: f6f351c324c767f36e0b
    Time: 4852ms
               Asset       Size  Chunks                    Chunk Names
    ec.app.bundle.js     991 kB       0  [emitted]  [big]  app
    ../index_ec.html  295 bytes          [emitted]
     [109] multi (webpack)-dev-server/client?http://localhost:8080 ./src/app.tsx 40 bytes {0} [built]
     [110] (webpack)-dev-server/client?http://localhost:8080 7.27 kB {0} [built]
     [111] ./node_modules/url/url.js 23.3 kB {0} [built]
     [117] ./node_modules/strip-ansi/index.js 161 bytes {0} [built]
     [119] ./node_modules/loglevel/lib/loglevel.js 7.74 kB {0} [built]
     [120] (webpack)-dev-server/client/socket.js 1.04 kB {0} [built]
     [150] (webpack)-dev-server/client/overlay.js 3.71 kB {0} [built]
     [155] (webpack)/hot nonrecursive ^\.\/log$ 170 bytes {0} [built]
     [156] (webpack)/hot/log.js 1.04 kB {0} [optional] [built]
     [157] (webpack)/hot/emitter.js 77 bytes {0} [built]
     [158] ./node_modules/events/events.js 8.33 kB {0} [built]
     [159] ./src/app.tsx 378 bytes {0} [built] [1 error]
     [160] ./node_modules/react/react.js 56 bytes {0} [built]
     [176] ./node_modules/react-dom/index.js 59 bytes {0} [built]
     [177] ./node_modules/react-dom/lib/ReactDOM.js 5.17 kB {0} [built]
        + 238 hidden modules

    ERROR in ./src/app.tsx
    (7,14): error TS2304: Cannot find name '___'.
    Child html-webpack-plugin for "..\index_ec.html":
         1 asset
           [0] ./node_modules/html-webpack-plugin/lib/loader.js!./src/template.html 607 bytes {0} [built]
           [1] ./node_modules/lodash/lodash.js 540 kB {0} [built]
           [2] (webpack)/buildin/global.js 509 bytes {0} [built]
           [3] (webpack)/buildin/module.js 517 bytes {0} [built]
Child mx:
    Hash: dfaf739f3315f55626b4
    Time: 4456ms
               Asset       Size  Chunks                    Chunk Names
    mx.app.bundle.js     991 kB       0  [emitted]  [big]  app
    ../index_mx.html  295 bytes          [emitted]
     [109] multi (webpack)-dev-server/client?http://localhost:8080 ./src/app.tsx 40 bytes {0} [built]
     [110] (webpack)-dev-server/client?http://localhost:8080 7.27 kB {0} [built]
     [111] ./node_modules/url/url.js 23.3 kB {0} [built]
     [117] ./node_modules/strip-ansi/index.js 161 bytes {0} [built]
     [119] ./node_modules/loglevel/lib/loglevel.js 7.74 kB {0} [built]
     [120] (webpack)-dev-server/client/socket.js 1.04 kB {0} [built]
     [150] (webpack)-dev-server/client/overlay.js 3.71 kB {0} [built]
     [155] (webpack)/hot nonrecursive ^\.\/log$ 170 bytes {0} [built]
     [156] (webpack)/hot/log.js 1.04 kB {0} [optional] [built]
     [157] (webpack)/hot/emitter.js 77 bytes {0} [built]
     [158] ./node_modules/events/events.js 8.33 kB {0} [built]
     [159] ./src/app.tsx 378 bytes {0} [built] [1 error]
     [160] ./node_modules/react/react.js 56 bytes {0} [built]
     [176] ./node_modules/react-dom/index.js 59 bytes {0} [built]
     [177] ./node_modules/react-dom/lib/ReactDOM.js 5.17 kB {0} [built]
        + 238 hidden modules

    ERROR in ./src/app.tsx
    (7,14): error TS2304: Cannot find name '___'.
    Child html-webpack-plugin for "..\index_mx.html":
         1 asset
           [0] ./node_modules/html-webpack-plugin/lib/loader.js!./src/template.html 607 bytes {0} [built]
           [1] ./node_modules/lodash/lodash.js 540 kB {0} [built]
           [2] (webpack)/buildin/global.js 509 bytes {0} [built]
           [3] (webpack)/buildin/module.js 517 bytes {0} [built]
webpack: Failed to compile.
hallgren commented 6 years ago

The owner of the test project has submitted a fix that uses custom @type from typescript o fix my issue.

JuDev3 commented 5 years ago

Hello, how have you solved the problem ? I have the same error : Cannot find name '___' Thanks

hallgren commented 5 years ago

@Julien2 The solution to this is not on the top of my mind. But looking at the test repo I linked to in the description I think this line solved the issue: declare function ___(str: string): any;

JuDev3 commented 5 years ago

@hallgren I've added declare function myFunctionName(str: string): any; into a new file i18n.d.ts It works perfectly ! Thanks !