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.

VS Code auto imports are wrong for absolute paths in E2E files

See original GitHub issue

Bug Report or Feature Request (mark with an x)

- [ x] bug report -> please search issues before submitting
- [ ] feature request

Also asked in Stack Overflow

Versions

Angular CLI: 6.0.8 Node: 8.11.1 OS: win32 x64 Angular: 6.0.9

Repro steps

  1. Create a new app using ng new

  2. Setup baseUrl:“./src” in the tsconfig file

  3. Import something to a file in src folder using autoimport Result: import { smt1 } from “app/core/services/smt1”; (OK)

  4. Import something to a file in e2e folder using autoimport Result: import { smt2 } from “…/e2e/smt2”; (NOK) Auto import path is relative to the baseUrl of the tsconfig.json and cannot be resolved when running the tests

  5. Setup baseUrl: “.” in tsconfig.json to have a common root for both src and e2e folders

  6. Imports now look like this respectively: import { smt1 } from “src/app/core/services/smt1”; (OK) import { smt2 } from “src/e2e/smt2”; (OK)

  7. Run npm run e2e Cannot find name ‘smt2’.

    at createTSError (<path>\node_modules\ts-node\src\index.ts:261:12) at getOutput (<path>\node_modules\ts-node\src\index.ts:367:40) at Object.compile (<path>\node_modules\ts-node\src\index.ts:557:11) at Module.m._compile (<path>\node_modules\ts-node\src\index.ts:439:43) at Module._extensions…js (module.js:663:10) at Object.require.extensions.(anonymous function) [as .ts] (<path>node_modules\ts-node\src\index.ts:442:12) at Module.load (module.js:565:32) at tryModuleLoad (module.js:505:12) at Function.Module._load (module.js:497:3) at Module.require (module.js:596:17)

Desired functionality

baseUrl: “.” in tsconfig.json should enable us to have root folder of the app as the base both in e2e and src folders. Other option would be to configure autoimports for src and e2e files separately, so that we can use absolute paths in src and relative in e2e folders.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
robvaneckcommented, Nov 21, 2018

Im also having this issue.

My VS Code User Settings .json is set to non-relative paths:

  "typescript.preferences.importModuleSpecifier": "non-relative",

So when I (auto) import a dependency… the paths look like

// auto import
import { AppPage } from 'e2e/src/app.po';

// instead of (old)
import { AppPage } from './app.po';

When running npm run e2e

I get this error:

  Error: Cannot find module 'e2e/src/app.po'

How do we make e2e run with non-relative paths?

1reaction
alexeaglecommented, Sep 4, 2018

I think the question is how to get a tsconfig.json into the e2e directory rather than tsconfig-e2e.json since the latter isn’t used by the editor, and the e2e directory really is a different root directory?

Read more comments on GitHub >

github_iconTop Results From Across the Web

VS Code auto imports not using absolute paths and not indented
When I type something that can be auto imported, as seen in the above GIF, the auto import doesn't keep things at the...
Read more >
Fix Python Relative Imports and Auto-completion in VSCode
In this video, you will learn how to properly handle Python relative imports without extending the sys. path. Additionally, you will learn ...
Read more >
VS Code tips — Automatically update import paths ... - YouTube
Today's VS Code tip: update imports for JavaScript and TypeScriptWhen you rename or move a JavaScript or TypeScript file, VS Code will ...
Read more >
JavaScript Programming with Visual Studio Code
Automatic imports speed up coding by suggesting available variables throughout your project and its dependencies. When you select one of these suggestions, ...
Read more >
How to get VS Code to not complain about "Cannot ... - Reddit
I've added an alias to $src so that I can import components from the root of my src directory instead of only with...
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