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.

having issue with dynamic import in nodemon with babel-node

See original GitHub issue

having issue with dynamic import in nodemon with babel-node here is my package.json file my package.json

  • nodemon -1.17.2:
  • node -v8.11.2:
  • Operating system/terminal environment:
  • Command you ran: nodemon --exec babel-node server/server.js --ignore public/

Expected behaviour:- should compile without error

Actual behaviour:- but throwing an error that is Unexpected token import

here is problem :- screenshot from 2018-05-23 17-59-44

i ran my server/server.js file with command babel server/server.js it is working fine pic:-
screenshot from 2018-05-23 18-08-04

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
loganfsmythcommented, May 25, 2018

Oh I’m sorry, it looks like you’d need to enable https://www.npmjs.com/package/babel-plugin-dynamic-import-node

The syntax-dynamic-import is just so Babel doesn’t throw a parse error, if you want to transform it into something that works on Node, you need a transform to do that.

0reactions
rizwan92commented, May 26, 2018

it works thanks @loganfsmyth . so here is some information about dynamic import in server side rendering with react and express. dynamic import already supports by webpack which bundles up the all the react application. but if you are using server side rendering which means compile the whole react application in server side and then send html string to the client , then babel wont understand the syntax import (‘./yourFile.js’). to make it work you need to use this https://www.npmjs.com/package/babel-plugin-dynamic-import-node plugin for node support. and you must use stage-3 preset. my babelrc config { “presets”: [“es2015”,“stage-2”,“stage-3”,“react”], “plugins”: [“dynamic-import-node”] }

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - Code spliting with dynamic imports still create big files
One possible solution to split the client code in files with a size smaller than 244Kb could be adding this entry to webpack.config.babel.js ......
Read more >
babel-plugin-dynamic-import-node Code Examples - Snyk
Learn more about how to use babel-plugin-dynamic-import-node, ... Snyk Code to scan source code in minutes - no build needed - and fix...
Read more >
Error [ERR_REQUIRE_ESM]: require() of ES Module not ...
Instead change the require of index.js to a dynamic import() which is available in all CommonJS modules" occurs because a package you are...
Read more >
Using ES6 syntax “import/export” in Node js with Babel
Additionally, I will be using Nodemon in this tutorial. Let's get right into it! In your terminal or console, you can run the...
Read more >
ts-node err_require_esm | The AI Search Engine You Control
ERR_REQUIRE_ESM - TypeScript + nodemon + ts-node + node-fetch ... babel.config.ts ... to a dynamic import() which is available in all CommonJS modules....
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