Skip to content

Commit

Permalink
feat: Allow use of require('ical-generator') without .default
Browse files Browse the repository at this point in the history
Closes #253
  • Loading branch information
sebbo2002 committed May 12, 2021
2 parents b7b6e5b + 64e0c33 commit 31833a6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,6 @@ npm run browser-test

## 🙋 FAQ

### I updated to `ical-generator@2.x.x` and now get `TypeError: ical is not a function` errors

If you still want to use `require()` to import in version 2 onwards, please use `require('ical-generator').default`.
The reason for this change is that from version 2 on, other objects such as types and interfaces required for typescript
are exported as well ([#247](https://github.com/sebbo2002/ical-generator/issues/247)).

### What's `Error: Can't resolve 'fs'`?
`ical-generator` uses the node.js `fs` module to save your calendar on the filesystem. In browser environments, you usually don't need this, so if you pass `null` for fs in your bundler. In webpack this looks like this:

Expand Down
9 changes: 8 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ import ICalCalendar, {ICalCalendarData} from './calendar';
*
* @param data Calendar data
*/
export default function (data?: ICalCalendarData): ICalCalendar {
function ical(data?: ICalCalendarData): ICalCalendar {
return new ICalCalendar(data);
}

export default ical;

export {
default as ICalAlarm,
ICalAlarmData,
Expand Down Expand Up @@ -102,3 +104,8 @@ export {
escape,
foldLines
} from './tools';

/* istanbul ignore else */
if (typeof module !== 'undefined') {
module.exports = Object.assign(ical, module.exports);
}

0 comments on commit 31833a6

Please sign in to comment.