SyntaxError: Cannot use import statement outside a module Angular 5 - angular5

We are developing an application in Angular5. Now we are integrating SSR with our project. We installed express engine and platform server, also followed every steps needed for SSR.
While we building the application it was successful. When we run the command npm run serve, it will call node server.js. At this time it is throwing the error as below:
node_modules#ng-bootstrap\ng-bootstrap\modal\modal-stack.js:1 import
{ DOCUMENT } from '#angular/common'; ^^^^^^
SyntaxError: Cannot use import statement outside a module
at Module._compile (internal/modules/cjs/loader.js:892:18)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
at Module.load (internal/modules/cjs/loader.js:812:32)
at Function.Module._load (internal/modules/cjs/loader.js:724:14)
at Module.require (internal/modules/cjs/loader.js:849:19)
at require (internal/modules/cjs/helpers.js:74:18)
It is ng-bootstrap module we use. Anyone can give clue why this error?
Thanks!

Related

Getting cannot use import statement outside a module while running npm script

I am using npm and installed "autoprefixer" package and added this script
"prefix:css":"postcss --use autoprefixer -b 'last 10 versions'
style/stylesheet.comp.css -o style/style.prefix.css"
to the package.json, but when I am trying to run it, I am getting the following error
getting this error
SyntaxError: Cannot use import statement outside a module
at Module._compile (internal/modules/cjs/loader.js:895:18)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14)
at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
at internal/main/run_main_module.js:17:11
import is a keyword not a function so it has a different syntax. See: https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Statements/import
Use
const autoprefixer = require('autoprefixer');

Unable to run npx for create-nuxt-app without it failing due to is-promise

I am attempting to create a nuxt app in the command line, going to build a Vue web app running off this and Vuetify. I am not sure what I am doing wrong but I run the exact scaffolding command that the docs tell me to run and it errors out everytime with this message.
PS C:\users\gman\documents\github> npx create-nuxt-app myappname
create-nuxt-app v2.15.0
✨ Generating Nuxt.js project in myappname
Trace: Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: C:\Users\GMan\AppData\Roaming\npm-cache\_npx\23248\node_modules\create-nuxt-app\node_modules\is-promise\index.js
require() of ES modules is not supported.
require() of C:\Users\GMan\AppData\Roaming\npm-cache\_npx\23248\node_modules\create-nuxt-app\node_modules\is-promise\index.js from C:\Users\GMan\AppData\Roaming\npm-cache\_npx\23248\node_modules\create-nuxt-app\node_modules\run-async\index.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename C:\Users\GMan\AppData\Roaming\npm-cache\_npx\23248\node_modules\create-nuxt-app\node_modules\is-promise\index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from C:\Users\GMan\AppData\Roaming\npm-cache\_npx\23248\node_modules\create-nuxt-app\node_modules\is-promise\package.json.
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1172:13)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Module.require (internal/modules/cjs/loader.js:1042:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (C:\Users\GMan\AppData\Roaming\npm-cache\_npx\23248\node_modules\create-nuxt-app\node_modules\run-async\index.js:3:17)
at Module._compile (internal/modules/cjs/loader.js:1156:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14) {
code: 'ERR_REQUIRE_ESM'
}
at C:\Users\GMan\AppData\Roaming\npm-cache\_npx\23248\node_modules\create-nuxt-app\cli.js:46:17
Has anyone else run into this, google searching is turning up nothing, figure I would check here to see if anyone know what might be up.
Thanks!
I determined that is-promise pushed a commit 2 hours ago that broke.
They are fixing it sounds like.

Node Modules not generated

I have created a new node (MERN) app on my mac osx. Im learning (from rails).
I don't know why, but whilst I do have a package.json file, I cannot generate a node_modules folder. I have tried all of the suggested answers in this post.
When I go to the terminal and test:
ls node_modules
I get a long list of all the modules listed in my package.json (but no node modules folder in my app file in atom).
That list includes all of my babel modules.
When I try to start the app, I get an error that arises out of my using import statements instead of require (which I should be able to do if babel were working).
node server.js
/Users/mr_may/server.js:1
(function (exports, require, module, __filename, __dirname) { import express from 'express';
^^^^^^
SyntaxError: Unexpected token import
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:390:7)
at startup (bootstrap_node.js:150:9)
Does anyone know how to configure a new node app so that it generates the node modules folder? Apart from the post above, I can't find any suggestions on how to work through this problem. The answers in the post linked above haven't worked.
hi you may want to make sure you are in the directory of your folder
e.g.
cd Desktop/My_Project
The safest way is the then run npm init get all the required things fill out and run npm install --save babel-core at this point you should be able to see the node_modules folder found in "Desktop/My_Project/node_modules"
Try this out and hope this helps :D

cannot find module in electron prebuilt 1.x but in 0.x (0.2 and 0.3

I have a small code, that run well in electron (using prebuild 0.3.5, and 0.25).
I upgrade to electron prebuild 1.1.0 and 1.2.0
I got error
Uncaught Exception:
Error: Cannot find module 'app'
at Module._resolveFilename (module.js:438:15)
at Function.Module._resolveFilename (/home/mervo/electron/midas-tron/node_modules/electron-prebuilt/dist/resources/electron.asar/common/reset-search-paths.js:47:12)
at Function.Module._load (module.js:386:25)
at Module.require (module.js:466:17)
at require (internal/module.js:20:19)
at Object. (/ho
I think there is a change in structure in 1.x, that I dont know, can help?
The correct way to require the app module in Electron v1.0.0+ is:
const { app } = require('electron');
The same applies to any other built-in Electron module you could previously require directly.

Error initializing noflo nodejs

I am getting the following error while trying to setup my node.js server. I am using the latest version of noflo and node.js. Is anyone else seeing this behaviour for NoFlo on Windows?
Here is the command and error:
*C:\Users\Johan\Source\Repos\HelloNoFlow>node node_modules.bin\noflo-nodejs-init --help
C:\Users\Johan\Source\Repos\HelloNoFlow\node_modules\.bin\noflo-nodejs-init:2 basedir=`dirname "$0"`*
SyntaxError: Unexpected token ILLEGAL
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
I believe you're following this guide - which has wrong instructions on the execution.
This works for me on Windows:
.\node_modules\.bin\noflo-nodejs-init --help"
This is because the target is a shell script instead of Javascript. Executing node <shell script> is not going to work.
Note: The same should apply to starting "noflo-nodejs".
UPDATES (19/2/17)
The guide link has changed to https://docs.flowhub.io/getting-started-node
I no longer work on the project that uses noflo, but I find that the script has been converted to CoffeeScript. So this workaround might not be needed anymore