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

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');

Related

New ReactNative App Triggers Bundler Error: error Unexpected token =

Every time I try to create a new React Native app, I receive this error in the Metro Bundler:
error Unexpected token =.
/Users/lukeschoenberger/repos/PodApp/node_modules/metro-cache/src/stores/HttpStore.js:31
static HttpError = HttpError;
^
SyntaxError: Unexpected token =
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/Users/lukeschoenberger/repos/PodApp/node_modules/metro-cache/src/stores/HttpGetStore.js:12:19)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
info Run CLI with --verbose flag for more details.
Process terminated. Press <enter> to close the window
I'm running: npx react-native run-ios.
When I create the script, I create the app, I run: npx react-native init AppName
I'm on node v14.17.1.
The startup script also says: success Successfully launched the app on the simulator
What am I doing wrong?
I had the same error because I was running on node v10.
After switching to node v14.17.5 (npm v6.14.14) via nvm, it solved the issue.
Can you verify you are really on v14.17.1?
For me, I tried using node v14.17.5 and it didn't work. I removed:
static HttpError = HttpError;
static NetworkError = NetworkError;
from node_modules/metro-config/node_modules/metro-cache/src/stores/HttpStore.js
and it worked.
Can use patch-package as well:
yarn patch-package metro-config/metro-cache

Cannot find npm module, after installing apisync-generator with npm

I've run into a wall with using AsyncAPI-Generator on a windows server.
I've been following these instructions and after successfully installing ag I needed to update the path the be able to access the CLI.
When running the cli I get an error saying that ag cannot find the npm module, despite being installed using npm.
C:\Users\jontia\workspace>ag cud.yml #asyncapi/java-spring-template
C:\Users\jontia\.sdkman\candidates\java\20.2.0.r11-grl\languages\js\bin\node_modules\#asyncapi\generator\node_modules\global-npm\index.js:11
var err = new Error("Cannot find module 'npm'")
^
Error: Cannot find module 'npm'
at throwNotFoundError (C:\Users\jontia\.sdkman\candidates\java\20.2.0.r11-grl\languages\js\bin\node_modules\#asyncapi\generator\node_modules\global-npm\index.js:11:13)
at exports (C:\Users\jontia\.sdkman\candidates\java\20.2.0.r11-grl\languages\js\bin\node_modules\#asyncapi\generator\node_modules\global-npm\index.js:39:5)
at Object.<anonymous> (C:\Users\jontia\.sdkman\candidates\java\20.2.0.r11-grl\languages\js\bin\node_modules\#asyncapi\generator\node_modules\global-npm\index.js:27:18)
at Module._compile (internal/modules/cjs/loader.js:1138:30)
at Object.<anonymous> (internal/modules/cjs/loader.js:1158:10)
at Module.load (internal/modules/cjs/loader.js:986:32)
at Function._load (internal/modules/cjs/loader.js:879:14)
at Module.require (internal/modules/cjs/loader.js:1026:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (C:\Users\jontia\.sdkman\candidates\java\20.2.0.r11-grl\languages\js\bin\node_modules\#asyncapi\generator\node_modules\npmi\npmi.js:1:14) {
code: 'MODULE_NOT_FOUND'
}
This doesn't make any sense to me, how can the npm module not be available when I'm using it?

npm run serve unexpected token ...options

I am trying to run IBM blockchain election system, Evote. link=https://github.com/IBM/evote.
when I am trying to run client by using "npm run serve". I am getting following error.
ahmed#ahmed-Inspiron-3580:~/evote/web-app/client$ npm run serve
> client#0.1.0 serve /home/ahmed/evote/web-app/client
> vue-cli-service serve
/home/ahmed/evote/web-app/client/node_modules/open/index.js:29
...options
^^^
SyntaxError: Unexpected token ...
at createScript (vm.js:74:10)
at Object.runInThisContext (vm.js:116:10)
at Module._compile (module.js:533:28)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/home/ahmed/evote/web-app/client/node_modules/#vue/cli-shared-utils/lib/openBrowser.js:9:14)
You are probably using a very old version of node.js. You can check the version by doing
node -v
you need to be using node 8 (it may not work with any version higher than that).
I would recommend using nvm as a mechanism for managing node versions. See https://github.com/nvm-sh/nvm

SyntaxError: Cannot use import statement outside a module Angular 5

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!

Assetic: Cannot find module 'less'

The problem:
I am using laravel 4 + basset for asset management (OSX).
i have added the twitter bootstrap to my composer as a dependency.
I want to compile the less files into a collection:
Basset::collection('TwitterBootstrap', function($collection)
{
// Collection definition.
$collection->add('../vendor/twbs/bootstrap/less/bootstrap.less');
})->apply('Less');
I then try to build the collection:
php artisan basset:build TwitterBootstrap
Which throws the error:
[Assetic\Exception\FilterException]
An error occurred while running:
'/usr/local/bin/node' '/private/var/folders/f4/xjby77695pbcgfdjfclfdqd40000gn/T/assetic_less5y7dnh'
Error Output:
module.js:340
throw err;
^
Error: Cannot find module 'less'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/private/var/folders/f4/xjby77695pbcgfdjfclfdqd40000gn/T/assetic_less5y7dnh:1:74)
at Module._compile (module.js:456:26)
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)
I have installed less globally - im unsure why this is throwing errors/what to fix (my path? a node config? an assetic config?)
I had the same problem and I solved it by installing less with npm :
npm install less
To use less globally, do not run "npm install less" at the root of your project.
Instead add a symlink to the global one (/home/{user}/node_modules/less/) in your project :
ln -s /home/{user}/node_modules/less/ /path/to/project/node_modules/less
ln -s /home/{user}/node_modules/less/bin/lessc /path/to/project/node_modules/less/.bin/lessc
How did you install less?
npm install less
Reference: https://npmjs.org/package/less
Edit... Just saw your footnote.
Another option would be to install lessPHP via composer and use LessphpFilter instead of LessFilter