Jest: Getting unexpected token 'export' from `node_modules/botframework-streaming` (ts-jest)
See original GitHub issueVersions
What package version of the SDK are you using.
└─┬ botframework-directlinejs@0.15.1
└── botframework-streaming@4.14.1
What nodejs version are you using
$» npm ls node -v
8.12.1
What browser version are you using What os are you using
MacOS Monterey 12.4
Describe the bug
In our project we include botframework-directlinejs@0.15.1
as dependency. When trying to execute jest
├── jest@28.1.3
└─┬ ts-jest@28.0.7
we’re getting
● Test suite failed to run
Jest encountered an unexpected token
Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.
Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.
By default "node_modules" folder is ignored by transformers.
Here's what you can do:
• If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
• If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/configuration
For information about custom transformations, see:
https://jestjs.io/docs/code-transformation
Details:
our-project/node_modules/botframework-streaming/node_modules/uuid/dist/esm-browser/index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){export { default as v1 } from './v1.js';
^^^^^^
SyntaxError: Unexpected token 'export'
at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1796:14)
at Object.<anonymous> (node_modules/botframework-streaming/src/utilities/protocol-base.ts:8:1)
To Reproduce
Steps to reproduce the behavior:
- install
botframework-directlinejs@0.15.1
- install and configure
jest
using as presetts-jest
- write any test
- got
Unexpected token 'export'
fromnode_modules/botframework-streaming/node_modules/uuid/dist/esm-browser/index.js:1
Expected behavior
node_modules/botframework-streaming/node_modules/uuid/dist/esm-browser/index.js:1
not causing trouble
Additional context
This is how we setup jest:
module.exports = {
// An array of directory names to be searched recursively up from the requiring module's location
// @see https://stackoverflow.com/a/51174924/1614677
moduleDirectories: ["node_modules", "src"],
// A preset that is used as a base for Jest's configuration
preset: "ts-jest",
// A list of paths to directories that Jest should use to search for files in
roots: ["<rootDir>/src"],
// A list of paths to modules that run some code to configure or set up the testing framework before each test
setupFilesAfterEnv: ["<rootDir>/jest.setup.ts"],
// The test environment that will be used for testing
testEnvironment: "jsdom",
// The glob patterns Jest uses to detect test files
testMatch: ["**/?(*.)+(spec|test).[tj]s?(x)"],
};
We’ve also tried adding this:
transformIgnorePatterns: [
"node_modules/(?!(botframework-streaming)/)",
],
with no success.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Unexpected token export, when import not compiled libraries ...
Issue : First of all, I'm not sure if this is a ts-jest issue or not, so sorry if I'm not reporting this...
Read more >Jest gives an error: "SyntaxError: Unexpected token export"
This means, that a file is not transformed through TypeScript compiler, e.g. because it is a JS file with TS syntax, or it...
Read more >TypeScript Jest: Unexpected Token Export - Reddit
I'm trying to run unit tests for a TypeScript project which uses another TypeScript project I've created as a dependency.
Read more >Jest SyntaxError: Unexpected token 'export'
This time I'm going to talk about a specific error: SyntaxError: Unexpected token 'export' .
Read more >syntaxerror: unexpected token 'export' ts-jest - You.com
I'm getting SyntaxError: Unexpected token 'export' on some node_modules , which are not transpiled (I guess?). I worked around this by adding these...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
hi @ramfattah thanks for the effort.
I have been able to solve this and shame on me 🤦 this wasn’t caused by
node_modules/botframework-streaming
butnode_modules/uuid
in the end.I mean the call trace is
botframework-streaming
==>uuid
(in the end isuuid
who is causing the issue).Sorry for the noise
Since we’ve already open this, let’s doc the thing (if this help someone)
👇
problem: Jest is raising:
For solving this:
.js
file usingexport
tsconfig.json
)Our problem was that I was setting
instead of
Hi @manuartero, I’m investigating this issue.