I recently switched from Babel to Typescript and am facing difficulties with importing a module from node_modules
. The generated .js
build does not include the code from the module I'm trying to import, specifically browser-cookies.
I used yarn to install the package: yarn add browser-cookies
. Then, in my attempt to import it into main.ts
, I wrote:
const cookies = require('browser-cookies');
(function() {
document.forms['number-generator'].addEventListener('submit', (ev) => {
ev.preventDefault();
if(!cookies.get('ab')) {
cookies.set('ab', 'true', { expires: 1 });
}
})
})();
Here is an excerpt from my package.json
file:
{
"name": "lucky-lotto-lander",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"build": "tsc src/app.ts --outFile dist/app.js --module amd --watch"
},
"dependencies": {
"@types/node": "^8.0.53",
"browser-cookies": "^1.1.0",
"copyfiles": "^1.2.0"
}
}
However, the resulting main.js
build does not have the necessary browser-cookies
code bundled. How can I address this issue?