简体   繁体   English

未捕获的语法错误:无法在模块外使用 import 语句。 将 typescript 文件导入 JavaScript 文件

[英]Uncaught SyntaxError: Cannot use import statement outside a module. import typescript file into JavaScript file

I am working on angular 10. I need to use typescript angular service in jQuery file.我正在研究 angular 10。我需要在 ZF590B4FDA2C30BE28ZDD3C7C7C7B 文件中使用 typescript angular 服务。 When I am importing TypeScript service file in jquery it gives me the error:当我在 jquery 中导入 TypeScript 服务文件时,它给了我错误:

Uncaught SyntaxError: Cannot use import statement outside a module

I am using below import statment in jQuery file:我在 jQuery 文件中使用以下导入语句:

import { priceFilteredByService } from "../../app/service/category-filtered-by/electronics/laptops/price-filtered-by-service";

priceFilteredByService is Angular typescript file. priceFilteredByService 是 Angular typescript 文件。 I need to access its function from a javascript file.我需要从 javascript 文件中访问它的 function。

You find below javascript file:您可以在 javascript 文件下方找到:

import { laptopsFilteredByService } from "../../app/service/category-filtered-by/electronics/laptops/laptops-filtered-by-service";
import { priceFilteredByService } from "../../app/service/category-filtered-by/electronics/laptops/price-filtered-by-service";

!(function ($) {
    laptopFilteredByService: laptopsFilteredByService;
    priceFilteredByService: priceFilteredByService;
    
    $(document).ready(function () {
      "use strict";
    
    $('#price-range-submit').hide();

    $("#min_price,#max_price").on('change', function () {

      var min_price_range = parseInt($("#min_price").val());

      var max_price_range = parseInt($("#max_price").val());

      this.priceFilteredByService.getPriceMinMaxFilter()
      this.priceFilteredByService.setMinAED(min_price_range);
      this.priceFilteredByService.setMaxAED(max_price_range);
      this.laptopFilteredByService.getSelectedFilters()  
      
    });
});

Looks like your javascript compiler does not consider this file a module.看起来您的 javascript 编译器不将此文件视为模块。 If you don't have already, you need to add compiler / bundler step to you workflow-如果您还没有,则需要将编译器/捆绑器步骤添加到您的工作流程中-

暂无
暂无

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

相关问题 运行编译的 Javascript 代码时,TypeScript 文件中出现“语法错误:无法在模块外使用导入语句”错误 - "SyntaxError: Cannot use import statement outside of a module" error in a TypeScript file when running compiled Javascript code 未捕获的语法错误:无法在模块外使用导入语句 - Javascript - Uncaught SyntaxError: Cannot use import statement outside a module - Javascript SyntaxError: 不能在模块外使用 import 语句。 我正在使用 typescript 和 discord js - SyntaxError: Cannot use import statement outside a module. I'm using typescript and discord js 未捕获的语法错误:无法在模块 Vue.js 单个组件文件之外使用导入语句 - Uncaught SyntaxError: Cannot use import statement outside a module Vue.js single component file 在 Javascript 中使用导入/导出的问题“未捕获的语法错误:无法在模块外使用导入语句” - Problem using import/export in Javascript "Uncaught SyntaxError: Cannot use import statement outside a module" JavaScript 导入错误 - 未捕获的 SyntaxError:无法在模块外使用导入语句 - JavaScript import error - Uncaught SyntaxError: Cannot use import statement outside a module 尝试在 Django 应用程序的 js 文件中导入 vue.js 时出现“未捕获的语法错误:无法在模块外使用导入语句” - “Uncaught SyntaxError: Cannot use import statement outside a module” when trying to import vue.js inside js file in Django app 未捕获的语法错误:无法在模块外使用 import 语句 - Uncaught SyntaxError: Cannot use import statement outside a module 未捕获的语法错误:无法在节点 js 中的模块外使用导入语句 - Uncaught SyntaxError: Cannot use import statement outside a module in node js 未捕获的语法错误:无法在具有 OpenLayers 的模块外部使用 import 语句 - Uncaught SyntaxError: Cannot use import statement outside a module with OpenLayers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM