首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SyntaxError:无法在Turborepo包中的模块外使用导入语句

SyntaxError:无法在Turborepo包中的模块外使用导入语句
EN

Stack Overflow用户
提问于 2022-07-22 09:17:42
回答 3查看 1K关注 0票数 0

我有一个打字稿“测试”包在涡轮增压器和它的进出口打字本功能。

因为它是涡轮增压器,所以它被复制到节点_模块/测试中。

当我试图运行import {func} from "test"时。它给了我这个错误,测试包的SyntaxError: Cannot use import statement outside a module. Ts配置是。

代码语言:javascript
复制
{
    "extends": "tsconfig/base.json",
    "compilerOptions": {
      "declaration": true,
      "target": "es6",
      "module": "commonjs",
      "moduleResolution": "node",
      "baseUrl": ".",
    },
    "include": ["**/*.ts"]
  }

此节点应用程序的Nodemon配置

代码语言:javascript
复制
{
  "watch": ["src"],
  "ignore": ["src/**/*.test.ts"],
  "ext": "ts,mjs,js,json,graphql",
  "exec": "tsc && node ./dist/index.js",
  "legacyWatch": true
}

但是,当我试图在nextjs项目中导入相同的内容时,其中包含在config中。

代码语言:javascript
复制
const withTM = require('next-transpile-modules')(['test'])

它工作得很好。

在我看来,在节点服务器端。当我包括来自node_modules的那个node_modules的时候。不会被转移的。

有办法解决这个问题吗?

我还试着使用tsc构建包,但将dist文件夹保存在包中似乎并不理想。

EN

回答 3

Stack Overflow用户

发布于 2022-07-23 11:25:22

Stack Overflow用户

发布于 2022-09-19 12:40:09

这对我有用。

包装/试验/包装

代码语言:javascript
复制
{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "./dist/index.js",
  "types": "./dist/index.d.ts",
  "scripts": {
    "build": "tsc",
    "dev": "tsc-watch --onSuccess tsc ",
    "postinstall": "tsc"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "tsc-watch": "^5.0.3"
  }
}
票数 0
EN

Stack Overflow用户

发布于 2022-10-30 17:05:46

对于节点服务器,我使用ts-node --transpile-only index.ts,它可以很好地处理.ts文件。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73077970

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档