planttheidea / fast-copy

A blazing fast deep object copier
MIT License
1.13k stars 31 forks source link

Problems with import #21

Closed IgorBabkin closed 4 years ago

IgorBabkin commented 5 years ago

I add fast-copy to my TS project and got this error. DesignElement.ts:125 Uncaught (in promise) TypeError: fast_copy_1.default is not a function. I've analyzed .js file and didn't find default import. But in declaration file it declares as default.

planttheidea commented 5 years ago

In what context are you using it (e.g., node, browser, etc)? And are you using commonjs or esm?

I ask because the main build uses commonjs, which does not have a .default property in the same way that the module build does because that uses esm.

Nixes commented 5 years ago

I'd just like to chime in to say that I'm having the same issue. And my ts config contains: "module": "commonjs", I am using it in a nodejs context. Let me know if you need any other details

planttheidea commented 5 years ago

Can you try specifying the full path to the module, e.g. import copy from 'fast-copy/dist/fast-copy.esm.js';? That should provide a work around.

Nixes commented 5 years ago

Thanks. It seems to get further but then there is some kind of syntax error with the export:

\node_modules\fast-copy\dist\fast-copy.esm.js:309
export default copy;
^^^^^^

SyntaxError: Unexpected token export
    at Module._compile (internal/modules/cjs/loader.js:703:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:770:10)
planttheidea commented 5 years ago

Well I just realized ... Are you using import syntax when you are setting module: commonjs in your config. Why aren't you using es2015 or esnext? Because that would could cause the error you're seeing.

planttheidea commented 4 years ago

Closing due to inactivity.