简体   繁体   English

Angular Datatables Cannot use import statement outside a module 错误

[英]Angular Datatables Cannot use import statement outside a module Error

I am trying to add angular datatables to a new test project.我正在尝试将 angular 数据表添加到新的测试项目中。 I have used the following commands:我使用了以下命令:

ng new test-app
cd test-app
ng add angular-datatables

I get the following output from the ng-add command:我从 ng-add 命令中得到以下 output:

~/projects/test-app (master) $ ng add angular-datatables
- Determining package manager...
i Using package manager: npm
- Searching for compatible package version...
√ Found compatible package version: angular-datatables@13.0.0.
- Loading package information from registry...
√ Package information loaded.
- Installing package...
√ Package successfully installed.
An unhandled exception occurred: Cannot use import statement outside a module
See "C:\Users\User\AppData\Local\Temp\ng-d8eINZ\angular-errors.log" for further details.

In the angular-errors.log file, I see the following error:在 angular-errors.log 文件中,我看到以下错误:

[error] C:\Users\User\projects\test-app\node_modules\angular-datatables\schematics\src\ng-add\index.js:1
import { chain } from '@angular-devkit/schematics';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (internal/modules/cjs/loader.js:979:16)
    at Module._compile (internal/modules/cjs/loader.js:1027:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at new ExportStringRef (C:\Users\User\projects\test-app\node_modules\@angular-devkit\schematics\tools\export-ref.js:19:25)
    at SchematicEngineHost._resolveReferenceString (C:\Users\User\projects\test-app\node_modules\@angular-devkit\schematics\tools\node-module-engine-host.js:95:21)
    at SchematicEngineHost._resolveReferenceString (C:\Users\User\projects\test-app\node_modules\@angular\cli\models\schematic-engine-host.js:62:22)
    at SchematicEngineHost.createSchematicDescription (C:\Users\User\projects\test-app\node_modules\@angular-devkit\schematics\tools\file-system-engine-host-base.js:174:34)
    at SchematicEngine.createSchematic (C:\Users\User\projects\test-app\node_modules\@angular-devkit\schematics\src\engine\engine.js:215:38)
    at CollectionImpl.createSchematic (C:\Users\User\projects\test-app\node_modules\@angular-devkit\schematics\src\engine\engine.js:70:29)
    at AddCommand.getSchematic (C:\Users\User\projects\test-app\node_modules\@angular\cli\models\schematic-command.js:134:27)
    at AddCommand.runSchematic (C:\Users\User\projects\test-app\node_modules\@angular\cli\models\schematic-command.js:315:32)
    at AddCommand.executeSchematic (C:\Users\User\projects\test-app\node_modules\@angular\cli\commands\add-impl.js:212:31)

I have tried this in Angular version 11.2.14 and 12.2.9 with the same result.我在 Angular 版本 11.2.14 和 12.2.9 中尝试过这个,结果相同。

Trying again in Angular 13.0.2, I get the following:在 Angular 13.0.2 中再次尝试,我得到以下信息:

~/projects/test-app (master) $ ng add angular-datatables
- Determining package manager...
i Using package manager: npm
- Searching for compatible package version...
√ Found compatible package version: angular-datatables@13.0.0.
- Loading package information from registry...
√ Package information loaded.
No terminal detected. '--skip-confirmation' can be used to bypass installation confirmation. Ensure package name is correct prior to '--skip-confirmation' option usage.
Command aborted.

Then, adding --skip-confirmation, I get the same error as before.然后,添加--skip-confirmation,我得到了和以前一样的错误。

How does one get past this error?如何克服这个错误?

I'm surprised no one has reported an answer.我很惊讶没有人报告答案。 I had this trouble too, but installing ng add @angular/material .我也遇到了这个麻烦,但是安装ng add @angular/material The key is the "No terminal detected."关键是“未检测到终端”。

I was using git bash.我正在使用 git bash。

I switched to a Windows PowerShell and it was fine.我切换到 Windows PowerShell 并且很好。 This is odd since I've been able to use ng add in git bash in the past.这很奇怪,因为我过去能够在 git bash 中使用 ng add 。 Not sure what is different now.不知道现在有什么不同。

On Windows I use Windows CMD this works for me.在 Windows 上,我使用Windows CMD这对我有用。 Git Bash does not work though and terminates with the same error: No terminal detected. Git Bash 不起作用,并以相同的错误终止:未检测到终端。 '--skip-confirmation'... '--跳过确认'...

Trying ng add @angular/material terminates with the same error in Git Bash.尝试ng add @angular/material在 Git Bash 中以相同的错误终止。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未捕获的语法错误:无法在 Angular 和 Firebase 中的模块外部使用导入语句 - Uncaught SyntaxError: Cannot use import statement outside a module in Angular & Firebase Angular 从版本 8 升级到 15。错误“无法在模块外使用导入语句” - Angular upgrade from version 8 to 15. Error "Cannot use import statement outside a module" WebdriverIO 和 Angular,在导入类的打字稿中编写 e2e 测试(不能在模块外使用 import 语句) - WebdriverIO and Angular, writing e2e tests in typescript that import classes (Cannot use import statement outside a module) SyntaxError:无法在 Angular/Nx/jest 应用程序中使用 @ionic-native/health 在模块外使用 import 语句 - SyntaxError: Cannot use import statement outside a module using @ionic-native/health in Angular/Nx/jest app 未捕获的语法错误:无法在 Angular 12 项目中的模块外部使用导入语句 - Uncaught SyntaxError: Cannot use import statement outside a module in Angular 12 project 更新到 Angular 13 后,无法在 Jest 中使用带有 date-fns 的模块外使用 import 语句 - Cannot use import statement outside a module with date-fns in Jest after updating to Angular 13 Angular.ts 和 Electron:SyntaxError:不能在模块外使用导入语句 - Angular.ts and Electron: SyntaxError: Cannot use import statement outside a module 不能在模块外使用 import 语句(Bazel + Concatjs + NgRx) - Cannot use import statement outside a module (Bazel + Concatjs + NgRx) 预呈现会导致 SyntaxError:无法在模块外使用 import 语句 - Prerendering causes a SyntaxError: Cannot use import statement outside a module Angular v13 带 nx 测试的玩笑 - 语法错误:无法在 Runtime.createScriptFromCode 的模块外使用导入语句 - Angular v13 Jest with nx test - SyntaxError: Cannot use import statement outside a module at Runtime.createScriptFromCode
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM