SyntaxError: Unexpected token export when testing typescript code with ES2015 module imports with jest
up vote
0
down vote
favorite
Im struggeling to get some code I work with tested.
In all my projects I use jest for testing. it works fine as long as I have javascript files but I do work with some packages containing typescript code. The code contains dependencies with ES2015 module imports and exports and when built its bundled with webpack where the target code still contain ES2015 module exports and imports
Jest runs on node and can´t handle ES2015 modules (yet) and I can not figure out how to configure either typescript babel or jest to transpile the dependency code into commonjs modules when I want to run my tests
I have spent an insane amount of time trying to figure this out so I appreciate all help I can get.
in this example I have cloned the jest example project for Typescript and modified it to contain a dependency containing ES2015 modules to illustrate the problem
tsconfig.json
{
"compilerOptions": {
"allowJs": true,
"module": "commonjs"
}
}
package.json
{
"devDependencies": {
"@types/jest": "^23.1.1",
"@types/node": "^10.12.3",
"jest": "*",
"typescript": "*",
"ts-jest": "*"
},
"dependencies": {
"lodash-es": "^4.17.11" //has es2015 exports
},
"jest": {
"moduleFileExtensions": [
"ts",
"tsx",
"js"
],
"transform": {
"^.+\.(ts|tsx)$": "ts-jest"
},
"globals": {
"ts-jest": {
"tsConfigFile": "tsconfig.json"
}
},
"testMatch": [
"**/__tests__/*.+(ts|tsx|js)">
]
}
}
wrap.ts
import {map} from "lodash-es";
export function wrap(a: number, b: number): number {
return map([a,b],i=>({i}));
}
wrap.test.ts
import {wrap} from "../sum"
it('wrap ', ()=> {
expect(wrap(1, 2)).toBe([{i:1},{i:1}]);
});
when running jest i get
export { default as add } from './add.js';
^^^^^^
SyntaxError: Unexpected token export
from a file in the dependency
any ideas on how to solve this?
typescript jestjs es6-modules
add a comment |
up vote
0
down vote
favorite
Im struggeling to get some code I work with tested.
In all my projects I use jest for testing. it works fine as long as I have javascript files but I do work with some packages containing typescript code. The code contains dependencies with ES2015 module imports and exports and when built its bundled with webpack where the target code still contain ES2015 module exports and imports
Jest runs on node and can´t handle ES2015 modules (yet) and I can not figure out how to configure either typescript babel or jest to transpile the dependency code into commonjs modules when I want to run my tests
I have spent an insane amount of time trying to figure this out so I appreciate all help I can get.
in this example I have cloned the jest example project for Typescript and modified it to contain a dependency containing ES2015 modules to illustrate the problem
tsconfig.json
{
"compilerOptions": {
"allowJs": true,
"module": "commonjs"
}
}
package.json
{
"devDependencies": {
"@types/jest": "^23.1.1",
"@types/node": "^10.12.3",
"jest": "*",
"typescript": "*",
"ts-jest": "*"
},
"dependencies": {
"lodash-es": "^4.17.11" //has es2015 exports
},
"jest": {
"moduleFileExtensions": [
"ts",
"tsx",
"js"
],
"transform": {
"^.+\.(ts|tsx)$": "ts-jest"
},
"globals": {
"ts-jest": {
"tsConfigFile": "tsconfig.json"
}
},
"testMatch": [
"**/__tests__/*.+(ts|tsx|js)">
]
}
}
wrap.ts
import {map} from "lodash-es";
export function wrap(a: number, b: number): number {
return map([a,b],i=>({i}));
}
wrap.test.ts
import {wrap} from "../sum"
it('wrap ', ()=> {
expect(wrap(1, 2)).toBe([{i:1},{i:1}]);
});
when running jest i get
export { default as add } from './add.js';
^^^^^^
SyntaxError: Unexpected token export
from a file in the dependency
any ideas on how to solve this?
typescript jestjs es6-modules
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Im struggeling to get some code I work with tested.
In all my projects I use jest for testing. it works fine as long as I have javascript files but I do work with some packages containing typescript code. The code contains dependencies with ES2015 module imports and exports and when built its bundled with webpack where the target code still contain ES2015 module exports and imports
Jest runs on node and can´t handle ES2015 modules (yet) and I can not figure out how to configure either typescript babel or jest to transpile the dependency code into commonjs modules when I want to run my tests
I have spent an insane amount of time trying to figure this out so I appreciate all help I can get.
in this example I have cloned the jest example project for Typescript and modified it to contain a dependency containing ES2015 modules to illustrate the problem
tsconfig.json
{
"compilerOptions": {
"allowJs": true,
"module": "commonjs"
}
}
package.json
{
"devDependencies": {
"@types/jest": "^23.1.1",
"@types/node": "^10.12.3",
"jest": "*",
"typescript": "*",
"ts-jest": "*"
},
"dependencies": {
"lodash-es": "^4.17.11" //has es2015 exports
},
"jest": {
"moduleFileExtensions": [
"ts",
"tsx",
"js"
],
"transform": {
"^.+\.(ts|tsx)$": "ts-jest"
},
"globals": {
"ts-jest": {
"tsConfigFile": "tsconfig.json"
}
},
"testMatch": [
"**/__tests__/*.+(ts|tsx|js)">
]
}
}
wrap.ts
import {map} from "lodash-es";
export function wrap(a: number, b: number): number {
return map([a,b],i=>({i}));
}
wrap.test.ts
import {wrap} from "../sum"
it('wrap ', ()=> {
expect(wrap(1, 2)).toBe([{i:1},{i:1}]);
});
when running jest i get
export { default as add } from './add.js';
^^^^^^
SyntaxError: Unexpected token export
from a file in the dependency
any ideas on how to solve this?
typescript jestjs es6-modules
Im struggeling to get some code I work with tested.
In all my projects I use jest for testing. it works fine as long as I have javascript files but I do work with some packages containing typescript code. The code contains dependencies with ES2015 module imports and exports and when built its bundled with webpack where the target code still contain ES2015 module exports and imports
Jest runs on node and can´t handle ES2015 modules (yet) and I can not figure out how to configure either typescript babel or jest to transpile the dependency code into commonjs modules when I want to run my tests
I have spent an insane amount of time trying to figure this out so I appreciate all help I can get.
in this example I have cloned the jest example project for Typescript and modified it to contain a dependency containing ES2015 modules to illustrate the problem
tsconfig.json
{
"compilerOptions": {
"allowJs": true,
"module": "commonjs"
}
}
package.json
{
"devDependencies": {
"@types/jest": "^23.1.1",
"@types/node": "^10.12.3",
"jest": "*",
"typescript": "*",
"ts-jest": "*"
},
"dependencies": {
"lodash-es": "^4.17.11" //has es2015 exports
},
"jest": {
"moduleFileExtensions": [
"ts",
"tsx",
"js"
],
"transform": {
"^.+\.(ts|tsx)$": "ts-jest"
},
"globals": {
"ts-jest": {
"tsConfigFile": "tsconfig.json"
}
},
"testMatch": [
"**/__tests__/*.+(ts|tsx|js)">
]
}
}
wrap.ts
import {map} from "lodash-es";
export function wrap(a: number, b: number): number {
return map([a,b],i=>({i}));
}
wrap.test.ts
import {wrap} from "../sum"
it('wrap ', ()=> {
expect(wrap(1, 2)).toBe([{i:1},{i:1}]);
});
when running jest i get
export { default as add } from './add.js';
^^^^^^
SyntaxError: Unexpected token export
from a file in the dependency
any ideas on how to solve this?
typescript jestjs es6-modules
typescript jestjs es6-modules
edited Nov 8 at 8:25
skyboyer
3,07611028
3,07611028
asked Nov 7 at 23:36
Magnus Siverbrant
5817
5817
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53199535%2fsyntaxerror-unexpected-token-export-when-testing-typescript-code-with-es2015-mo%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown