Comments (3)
I wasn't able to duplicate this in a project using TypeScript 2.7.2.
Can you provide a code sample that causes this error?
from es6-error.
I am seeing this error as well in Typescript 2.7.2. It appears when I run tests with the following command:
mocha -r ts-node/register -r tsconfig-paths/register test/**/*.test.ts
Here is a (hopefully useful) snippet of the stack trace:
at Module._compile (module.js:662:30)
at Module.m._compile (C:\Dev\senalysis-common\node_modules\ts-node\src\index.ts:402:23)
at Module._extensions..js (module.js:673:10)
at Object.require.extensions.(anonymous function) [as .ts] (C:\Dev\senalysis-common\node_modules\ts-node\src\index.ts:405:12)
at Module.load (module.js:575:32)
at tryModuleLoad (module.js:515:12)
at Function.Module._load (module.js:507:3)
at Module.require (module.js:606:17)
at require (internal/module.js:11:18)
Here is the class from which the error is thrown:
import ExtendableError from 'es6-error';
import {FacebookApiError} from 'models/facebook';
export class FacebookError extends ExtendableError {
fbTraceId?: string;
constructor(error: FacebookApiError) {
super(error.error_user_msg);
this.fbTraceId = error.fbtrace_id;
}
}
I copied the ExtendableError internals into my own class, BaseError, and extended that instead. This gives no error.
export class BaseError extends Error {
constructor(message = '') {
super(message);
// extending Error is weird and does not propagate `message`
Object.defineProperty(this, 'message', {
configurable: true,
enumerable : false,
value : message,
writable : true,
});
Object.defineProperty(this, 'name', {
configurable: true,
enumerable : false,
value : this.constructor.name,
writable : true,
});
if (Error.hasOwnProperty('captureStackTrace')) {
Error.captureStackTrace(this, this.constructor);
return;
}
Object.defineProperty(this, 'stack', {
configurable: true,
enumerable : false,
value : (new Error(message)).stack,
writable : true,
});
}
}
import {BaseError} from './baseError';
import {FacebookApiError} from 'models/facebook';
export class FacebookError extends BaseError {
fbTraceId?: string;
constructor(error: FacebookApiError) {
super(error.error_user_msg);
this.fbTraceId = error.fbtrace_id;
}
}
from es6-error.
TL;DR: Turn on esModuleInterop
compiler option. If this is not an option, go ahead copy-and-paste.
Take at a look at this post.
babel-plugin-add-module-exports
doesn't play well with TypeScript.
Hope it helps.
from es6-error.
Related Issues (18)
- Curious about choices HOT 3
- Unable to alter stack trace. HOT 2
- no babelrc / babel in packages HOT 2
- babel config causes error with React Native HOT 1
- jsnext:main should not point to completely untranspiled code HOT 5
- jsnext:main usage HOT 6
- TypeError: Cannot read property 'prototype' of undefined"," at __extends HOT 6
- Unable to import using TypeScript on nodejs HOT 18
- Does not work in combination with longjohn HOT 5
- Strategy for `name` property given uglification? HOT 2
- Breaking changes for 4.1.0 behavior HOT 8
- Integration tests
- TypeError on 4.1.0 and 4.1.1 (but not 4.0.2) HOT 1
- `.message` is not defined HOT 3
- Consider deprecating this package HOT 2
- pkg.main, pkg.module are incompatible, so require("es6-error") behaves differently under Rollup/Webpack
- dist was not built on last publish HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from es6-error.