Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not work require().default #10

Closed
den67rus opened this issue Aug 12, 2019 · 1 comment
Closed

Not work require().default #10

den67rus opened this issue Aug 12, 2019 · 1 comment

Comments

@den67rus
Copy link

I use typescript and get this error:

const userAgent = new user_agents_1.default();
                  ^
TypeError: user_agents_1.default is not a constructor
    at Object.<anonymous> (C:\Users\user\Desktop\new\sdfsdf.js:4:19)
    at Module._compile (internal/modules/cjs/loader.js:759:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:770:10)
    at Module.load (internal/modules/cjs/loader.js:628:32)
    at Function.Module._load (internal/modules/cjs/loader.js:555:12)
    at Function.Module.runMain (internal/modules/cjs/loader.js:822:10)
    at internal/main/run_main_module.js:17:11

code before compilation:

import UserAgent from 'user-agents';

const userAgent = new UserAgent();
console.log(userAgent.toString()); //
console.log(JSON.stringify(userAgent.data, null, 2));

code after compilation typescript:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const user_agents_1 = require("user-agents");
const userAgent = new user_agents_1.default();
console.log(userAgent.toString()); //
console.log(JSON.stringify(userAgent.data, null, 2));

I think it has something to do with: babel/babel#2212

I think this can be fixed using the plugin https://www.npmjs.com/package/babel-plugin-add-module-exports with a parameter addDefaultProperty

@den67rus
Copy link
Author

Decision:

import * as UserAgent from 'user-agents';

const userAgent = new UserAgent();
console.log(userAgent.toString()); //
console.log(JSON.stringify(userAgent.data, null, 2));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant