I am trying to use the Globalize library with webpack 2 in a TypeScript project. The typescript/Webpack 2 setup already works, however, when importing and accessing Globalize, I am getting the following error message when running webpack:
ERROR in ./.tmp-globalize-webpack/C--Projects-webpack2-testing-app-index.ts
(1,1): error TS2304: Cannot find name 'module'.
ERROR in ./app/index.ts
(2,23): error TS7016: Could not find a declaration file for module 'globalize'. 'C:\Projects\webpack2-testing\node_modules\globalize\dist\node-main.js' implicitly has an 'any' type.
So I tried installing the globalize types:
npm install --save-dev @types/globalize
Now I get the following error:
ERROR in ./.tmp-globalize-webpack/C--Projects-webpack2-testing-app-index.ts
(1,1): error TS2304: Cannot find name 'module'.
ERROR in ./app/index.ts
(2,23): error TS2306: File 'C:/Projects/webpack2-testing/node_modules/@types/globalize/index.d.ts' is not a module.
Unfotunately this is all very new to me. Don't know if I should check webpack or typings or globalize or typescript...
This is my package.json:
{
"name": "webpack2-testing",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack --config webpack-config.js"
},
"devDependencies": {
"cldr-data": "^30.0.4",
"globalize": "^1.2.2",
"globalize-webpack-plugin": "^0.3.10",
"html-webpack-plugin": "^2.28.0",
"ts-loader": "^2.0.0",
"typescript": "^2.1.6",
"webpack": "^2.2.1"
}
}
and the index.ts:
import Globalize from "globalize";
function component () {
let element = document.createElement('div');
let currencyFormatter = Globalize.currencyFormatter( "USD" );
element.innerHTML = currencyFormatter( 69900 );
return element;
}
document.body.appendChild(component());
The complete project files (including webpack-config) are available at this github repository.
Note: This question arose while trying to solve a question I asked previously. If this works, it could also resolve my previous question.