I have a TypeScript project and I'm trying to use the following project: https://github.com/Simonwep/pickr
As per project description I have done the following:
import '@simonwep/pickr/dist/themes/nano.min.css'; // 'nano' theme
import {Pickr} from '@simonwep/pickr';
I also declared this in a separate file:
declare module '@simonwep/pickr';
Now when I try to use the library I see the following in Firefox console:
TypeError: pickr_min_1 is undefined
Edited 23 Oct 2019. Managed to fix the above by using
import Pickr from '@simonwep/pickr';
Now when I try to build the project I see the following error:
[!] Error: 'default' is not exported by node_modules\@simonwep\pickr\dist\pickr.
min.js
https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module
I'm new to Typescript and npm, so now sure what's the correct approach to import such kind of project in my TypeScript project. Any help will be appreciated.
Below are my configuration files:
//dev conf
import commoncfg from './conf-common';
import serve from 'rollup-plugin-serve';
import livereload from 'rollup-plugin-livereload';
import copy from 'rollup-plugin-cpy';
import staticSite from 'rollup-plugin-static-site';
commoncfg[0].plugins.push(
staticSite({
template: { path: 'test.html' },
dir: 'dist'
}),
copy({
files: ['*.jpg'],
dest: 'dist'
}),
serve('dist'),
livereload()
);
// only generate UMD during dev
commoncfg[0].output.splice(0, 1);
commoncfg.pop();
export default commoncfg;
prod conf:
import { terser } from "rollup-plugin-terser";
import copy from 'rollup-plugin-cpy';
import commoncfg from './conf-common';
commoncfg[0].plugins.push(
terser(),
copy({
files: ['LICENSE', 'README.md'],
dest: 'dist'
}),
);
commoncfg[0].output.pop();
commoncfg[1].plugins.push(
terser(),
);
export default commoncfg;
conf-common.js:
import pkg from './package.json';
import del from 'rollup-plugin-delete';
import typescript from 'rollup-plugin-typescript2';
import svgo from 'rollup-plugin-svgo';
import generatePackageJson from 'rollup-plugin-generate-package-json'
import postcss from 'rollup-plugin-postcss';
import commonjs from 'rollup-plugin-commonjs';
import nodeResolve from 'rollup-plugin-node-resolve';
const outputDir = "./dist/";
let leanPkg = Object.assign({}, pkg);
leanPkg.scripts = {};
leanPkg.devDependencies = {};
const banner =
`/* **********************************
Test
********************************** */`;
export default [
{
input: 'src/index.ts',
plugins: [
del({ targets: 'dist/*' }),
typescript({
useTsconfigDeclarationDir: true,
clean: true
}),
nodeResolve(),
commonjs({
include: 'node_modules/**', // Default: undefined
sourceMap: true, // Default: true
namedExports: { 'node_modules/@simonwep/pickr' :['pickr'] }
}),
postcss(),
svgo(),
generatePackageJson({
baseContents: leanPkg
})],
output: [
{
file: outputDir + pkg.module,
format: 'es',
banner: banner,
},
{
file: outputDir + pkg.main,
name: pkg.name,
format: 'umd',
sourcemap: true,
banner: banner,
},
]
},
{
input: 'src/index.ts',
plugins: [
typescript({
useTsconfigDeclarationDir: true,
clean: true
}),
postcss({
extensions: [ '.css' ]
}),
svgo(),
generatePackageJson({
baseContents: leanPkg
})],
output: [
{
file: outputDir + pkg.main,
name: pkg.name,
format: 'umd',
banner: banner
},
]
}
];