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 issue in nodejs ts app

See original GitHub issue
^^^^^^

SyntaxError: Unexpected token 'export'```

npm ver:^1.14.3

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
developitcommented, Oct 9, 2020

This isn’t a problem in Microbundle, it’s a misconfiguration. Microbundle isn’t being run when the module is built, it’s just relying on tsc.

You need a package.json like this:

{
  "source": "index.ts", // source code
  "main": "./dist/linq.js", // old node/webpack
  "module": "./dist/linq.mjs", // for bundlers
  "exports": "./dist/linq.mjs", // for node import()
  "scripts": {
    "build": "microbundle"
  }
}
0reactions
kutyelcommented, Jan 12, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot import module in nodejs with typescript - Stack Overflow
You just need to run below command in terminal : npm install @types/node.
Read more >
Common TypeScript module problems and how to solve them
Problem 1: Irregular location of dependencies​​ Sometimes, however, modules are not directly located under the baseUrl . As an example, take a ...
Read more >
Documentation - ECMAScript Modules in Node.js - TypeScript
This code works in CommonJS modules, but will fail in ES modules because relative import paths need to use extensions. As a result,...
Read more >
Fix Cannot use import statement outside a module using Node ...
One of the solutions, if you are using typescript, is to export and import your modules in a commonjs way. // mymodule.tsclass MyModule...
Read more >
SyntaxError: Cannot use import statement outside a module ...
I use nextjs import koa from 'koa' import next from 'next' import clear from 'clear' import body from 'koa-bodyparser' import cors from ...
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