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.

import * as not working

See original GitHub issue

🐞 bug report

Affected Package

The issue is caused by package @angular/....

Is this a regression?

Yes, the previous version in which this bug was not present was: no idea

Description

I am using this utils to show configuration and run local test, It is working fine as a standalone (without angular). URL : https://github.com/indraraj26/automate-ng-build-process

import * as chalk from 'chalk';
import * as env from './src/environments/environment';
import * as envStaging from './src/environments/environment.staging';
import * as envProduction from './src/environments/environment.prod';
import * as envDev from './src/environments/environment.dev';

πŸ”¬ Minimal Reproduction

https://stackblitz.com/...

πŸ”₯ Exception or Error




D:\test\latest\ng-test>npm run ts-node automate

> test-@0.1.0 ts-node D:\test\latest\ng-test
> ts-node "automate"

D:\test\latest\ng-test\automate.ts:12
import * as chalk from 'chalk';
       ^

SyntaxError: Unexpected token *
    at Module._compile (internal/modules/cjs/loader.js:721:23)

🌍 Your Environment

Angular Version:




>ng --version

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / β–³ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 9.0.3
Node: 10.16.0
OS: win32 x64

Angular: 9.0.2
... animations, common, compiler, compiler-cli, core, forms
... language-service, localize, platform-browser
... platform-browser-dynamic, router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.900.3
@angular-devkit/build-angular     0.900.3
@angular-devkit/build-optimizer   0.900.3
@angular-devkit/build-webpack     0.900.3
@angular-devkit/core              9.0.3
@angular-devkit/schematics        9.0.3
@angular/cdk                      8.2.3
@angular/cli                      9.0.3
@angular/material                 8.2.3
@ngtools/webpack                  9.0.3
@schematics/angular               9.0.3
@schematics/update                0.900.3
rxjs                              6.5.4
typescript                        3.7.5
webpack                           4.41.2

Anything else relevant?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
petebacondarwincommented, May 29, 2020

@indraraj26 - this is because ts-node reads the tsconfig.json file by default and in that file you will find "module": "esnext".

So when ts-node compiles the TS file the output JS, which node is trying to run, will include the import statement. The two solutions are:

  1. Run node with ES modules support turned on. (See https://blog.logrocket.com/es-modules-in-node-js-12-from-experimental-to-release/)
  2. Create a separate tsconfig.json and pass this to ts-node via the -p flag.
1reaction
indraraj26commented, Jun 2, 2020

Thank you @petebacondarwin . it is resolved with second option now my util will be helpful for me/others in future.

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - Import not Working - Stack Overflow
In python all modules have their own global namespaces, and A namespace containing all the built-in names is created, and module don't shareΒ ......
Read more >
5. The import system β€” Python 3.11.1 documentation
Python code in one module gains access to the code in another module by the process of importing it. The import statement is...
Read more >
Traps for the Unwary in Python's Import System
I'm using a similar layout described here and using explicit relative imports in my tests, however I'm running into numerous problems when I...
Read more >
Fix problems importing mail - Gmail Help - Google Support
Quick fixes to try first Β· On your computer, open Gmail. Β· In the top right, click Settings Settings and then See all...
Read more >
@import not working | Apple Developer Forums
In general when seing the error "use of '@import' when modules are disabled" it means that at least one of the targets that...
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