question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeScript - importing package failed on "Module parse failed: Unexpected token"

See original GitHub issue

Current behavior

I import npm package with additional functions and I get error:

Error: Webpack Compilation Error
../node_modules/cypress-somecompany-utils/src/env.ts 1:22
Module parse failed: Unexpected token (1:22)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> export function getEnv<TEnv, K extends keyof TEnv>(key: K): TEnv[K] {
.
.
.

I do not face this issue when I use @cypress/webpack-preprocessor. My target is to get rid of this preprocessor to increase build performance.

Desired behavior

I can import typescript packages.

Test code to reproduce

import * as utils from “cypress-somecompany-utils”;

Cypress Version

8.4.1

Other

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
adi518commented, May 30, 2022

Just chiming in on this. I got this error after the target on my main tsconfig.json was changed to a later target than es5. My Cypress tsconfig.jsoon inherits from that file and so I got the error. I simply overrode the target for Cypress and set it back to es5.

0reactions
sainthkhcommented, Nov 1, 2021

Closing because of the inactivity.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack failed to parse TypeScript module: Unexpected token
From what I can see, the module parsing error points to a line in my index.ts file. However, this file has no syntax...
Read more >
Module parse failed: Unexpected token Emberjs - Build Issues
I currently have an issue in an addon which I'm trying to convert to an Emberjs addon to the V2 version. It's a...
Read more >
module parse failed: unexpected token (1:0) you may need an ...
Answer. The root cause is that your Typescript rule isn't matching (“currently no loaders are configured to process this file”), so Webpack is...
Read more >
Internal Packages - Turborepo
ts Module parse failed: Unexpected token (1:21) You may need an appropriate loader to handle this file type, currently no loaders are configured ......
Read more >
TypeStrong/ts-loader - Gitter
I'm using Typescript 2.0.3, with ts-loader 0.8.2 and webpack 1.13.2, ... Module parse failed: Unexpected token (2:9) You may need an appropriate loader...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found