babel-node not transpiling lerna imported code - javascript

I´m using lerna with some packages:
packages
- server
- authenticator
- graphql
server is my current project and authenticator and graphql are imported modules.
Here is my server package.json:
{
"name": "#monorepo/server",
"version": "3.0.0",
"private": true,
"scripts": {
"start": "nodemon --exec \"cd ./src && babel-node server.js",
"lint": "eslint ."
},
"dependencies": {
"#monorepo/authenticator": "3.0.0",
"#monorepo/graphql": "3.0.0",
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-3": "^6.24.1",
"bcryptjs": "^2.4.3",
"body-parser": "^1.17.2",
"connect-mongo": "^2.0.0",
"crypto": "^1.0.1",
"express": "^4.15.3",
"jwt-simple": "^0.5.1",
"mongoose": "^5.0.10",
"morgan": "^1.8.2",
"nodemailer": "^4.6.0",
"passport": "^0.4.0",
"passport-jwt": "^4.0.0",
"path": "^0.12.7",
"validator": "^9.1.1"
}
}
My src/server.js file:
import express from "express";
import appGraphQL from "#monorepo/graphql/src";
import * as authenticator from "#monorepo/authenticator";
const app = express();
app.listen(3000, () => {
console.log(`Find the server at: http://localhost:3000`);
});
My graphql/src/index.js:
import graphqlHTTP from "express-graphql";
... some stuff here...
My authenticator/src/index.js:
import passport from "passport";
import passportJWT from "passport-jwt";
import jwt from "jwt-simple";
import bcrypt from "bcryptjs";
import crypto from "crypto";
import mongoose from "mongoose";
... some stuff here...
When running
$ yarn start
import passport from "passport";
^^^^^^
SyntaxError: Unexpected token import
at Object.exports.runInThisContext (vm.js:76:16)
at Module._compile (module.js:542:28)
at loader (D:\monorepo\node_modules\babel-register\lib\node.js:144:5)
at Object.require.extensions.(anonymous function) [as .js] (D:\monorepo\node_modules\babel-register\lib\node.js:154:7)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (D:/monorepo/packages/pageserver/src/server.js:24:1)
at Module._compile (module.js:570:32)
at loader (D:\monorepo\node_modules\babel-register\lib\node.js:144:5)
at Object.require.extensions.(anonymous function) [as .js] (D:\monorepo\node_modules\babel-register\lib\node.js:154:7)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
Can´t understand why is babel-node transpiling the graphql package and is not transpiling the authenticator package.
Is this a bug in babel-node ? What am I missing here ?
PS: Laravel internally use symlinks to modules. I´m using Windows 10.

Related

Unexpected token 'export' when trying to use the Preact plugin in Next.js

I am currently trying to migrate a Next.js project from React --> Preact.
I have added next-plugin-preact as a dependency and I changed my config also.
Here is the next.config.js:
// #ts-check
const configureBundleAnalyzer = require("#next/bundle-analyzer");
const withPreact = require("next-plugin-preact");
/** #type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
swcMinify: true,
compress: true,
images: {
domains: ["firebasestorage.googleapis.com", "localhost", "lh3.googleusercontent.com", "source.unsplash.com"],
},
i18n: {
locales: ["en"],
defaultLocale: "en",
},
};
const withBundleAnalyzer = configureBundleAnalyzer({ enabled: process.env.ANALYZE_BUNDLE === "true" });
module.exports = withBundleAnalyzer(withPreact(nextConfig));
And then I tried to run pnpm run build but it did nothing. Just killed the script right away.
Then again I tried to run the dev server with pnpm run dev but it threw this error:
:\Default_Folders\Desktop\Projects\Javascript + Dart\AppName\web\node_modules\.pnpm\preact#10.11.3\node_modules\preact\compat\server.browser.js:1
export {
^^^^^^
SyntaxError: Unexpected token 'export'
at internalCompileFunction (node:internal/vm:74:18)
at wrapSafe (node:internal/modules/cjs/loader:1141:20)
at Module._compile (node:internal/modules/cjs/loader:1182:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
at Module.load (node:internal/modules/cjs/loader:1081:32)
at Module._load (node:internal/modules/cjs/loader:922:12)
at Module.require (node:internal/modules/cjs/loader:1105:19)
at require (node:internal/modules/cjs/helpers:103:18)
at Object.<anonymous> (D:\Default_Folders\Desktop\Projects\Javascript + Dart\AppName\web\node_modules\.pnpm\next#13.1.5_ive3jjn476xyi3ikfsqwmh5x74\node_modules\next\dist\server\render.js:7:45) at Module._compile (node:internal/modules/cjs/loader:1218:14)
I tried to look into the file in preact/compat/server.browser.js and this is what's present:
export {
renderToString as renderToStaticMarkup, renderToString
} from 'preact-render-to-string';
So I tried to temporarily just change the contents of the file to:
const {
renderToString: renderToStaticMarkup, renderToString
} = require('preact-render-to-string');
module.exports = { renderToStaticMarkup, renderToString }
and then it threw this error:
Error: Next.js requires react >= 18.2.0 to be installed.
at Object.<anonymous> (D:\Default_Folders\Desktop\Projects\Javascript + Dart\AppName\web\node_modules\.pnpm\next#13.1.5_ive3jjn476xyi3ikfsqwmh5x74\node_modules\next\dist\build\webpack-config.js:1756:11)
at Module._compile (node:internal/modules/cjs/loader:1218:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
at Module.load (node:internal/modules/cjs/loader:1081:32)
Here is my package.json if needed:
{
"name": "app_name",
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"browserslist": [
"chrome 90",
"edge 90",
"firefox 90",
"opera 90",
"safari 14"
],
"dependencies": {
"#next/font": "latest",
"#react-icons/all-files": "^4.1.0",
"firebase": "^9.14.0",
"next": "^13.1.5",
"next-plugin-preact": "^3.0.7",
"nprogress": "^0.2.0",
"preact": "^10.11.3",
"preact-render-to-string": "^5.2.6",
"react": "npm:#preact/compat#^17.1.2",
"react-dom": "npm:#preact/compat#^17.1.2",
"react-hot-toast": "^2.4.0",
"react-ssr-prepass": "npm:preact-ssr-prepass#^1.2.0",
"sharp": "^0.31.3"
},
"devDependencies": {
"#next/bundle-analyzer": "^13.1.2",
"#types/node": "^18.11.9",
"#types/nprogress": "^0.2.0",
"#types/react": "^18.0.25",
"#typescript-eslint/eslint-plugin": "^5.46.0",
"autoprefixer": "^10.4.13",
"eslint": "^8.28.0",
"eslint-config-next": "^13.0.5",
"postcss": "^8.4.19",
"prettier": "^2.8.0",
"prettier-plugin-tailwindcss": "^0.2.0",
"tailwindcss": "^3.2.4",
"typescript": "^4.9.3"
}
}
Can anyone help?

How to fix "cannot find module'./node'' while compiling with pkg

the nodejs script works when I do node main.js but when I compile it into an executable with pkg it gives me this error :
pkg/prelude/bootstrap.js:1876
throw error;
^
Error: Cannot find module './node'
Require stack:
C:\snapshot\project\node_modules\hookcord\node_modules\snekfetch\src\index.js
C:\snapshot\project\node_modules\hookcord\src\fire.js
C:\snapshot\project\node_modules\hookcord\src\index.js
C:\snapshot\project\node_modules\hookcord\index.js
C:\snapshot\project\main.js
If you want to compile the package/file into executable, please pay attention to compilation warnings and specify a literal in 'require' call. 2) If you don't want to compile the package/file into executable and want to 'require' it from filesystem (likely plugin), specify an absolute path in 'require' call using process.cwd() or process.execPath.
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function._resolveFilename (pkg/prelude/bootstrap.js:1955:46)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at Module.require (pkg/prelude/bootstrap.js:1855:31)
at require (node:internal/modules/cjs/helpers:102:18)
at Object. (C:\snapshot\project\node_modules\hookcord\node_modules\snekfetch\src\index.js:3:19)
at Module._compile (pkg/prelude/bootstrap.js:1930:22)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\snapshot\project\node_modules\hookcord\node_modules\snekfetch\src\index.js',
'C:\snapshot\project\node_modules\hookcord\src\fire.js',
'C:\snapshot\project\node_modules\hookcord\src\index.js',
'C:\snapshot\project\node_modules\hookcord\index.js',
'C:\snapshot\project\main.js'
],
pkg: true
}
I have a similar error while packaging a NestJS application.
Here is my package.json file
{
"bin": "dist/main.js",
"pkg": {
"assets": [
"node_modules/**/*"
],
"outputPath": "bin",
"scripts": "dist/**/*.js",
"targets": [
"node14-linux-x64",
"node14-macos-x64"
]
},
"scripts": {
"prebuild": "rimraf dist",
"build": "nest build",
"build2": "pkg package.json",
"start": "nest start --watch",
"start:dev": "nest start --watch",
"start:prod": "node dist/main",
},
"dependencies": {
"#nestjs/common": "^7.0.0",
"#nestjs/core": "^7.0.0",
"#nestjs/platform-express": "^7.0.0",
"#nestjs/schedule": "^0.4.3",
"#nestjs/typeorm": "^7.1.4",
"#sentry/node": "^6.7.2",
"#sentry/tracing": "^6.7.2",
"axios": "^0.21.1",
"class-validator": "^0.12.2",
"fast-speedtest-api": "^0.3.2",
"jsonpath": "^1.1.0",
"moment": "^2.29.1",
"mysql": "^2.18.1",
"mysql2": "^2.2.5",
"querystring": "^0.2.1",
"queue-system": "^3.0.2",
"rimraf": "^3.0.2",
"rxjs": "^6.5.4",
"typeorm": "^0.2.27",
"winston": "^3.3.3",
"xml-js": "^1.6.11",
"xml2json": "^0.12.0"
},
"devDependencies": {
"#nestjs/cli": "^7.0.0",
"#nestjs/schematics": "^7.0.0",
"#nestjs/testing": "^7.0.0",
"#types/express": "^4.17.3",
"#types/node": "^13.9.1",
"#typescript-eslint/eslint-plugin": "3.9.1",
"#typescript-eslint/parser": "3.9.1",
"eslint": "7.7.0",
"eslint-plugin-import": "^2.20.1",
"ts-loader": "^6.2.1",
"ts-node": "9.0.0",
"tsconfig-paths": "^3.9.0",
"typescript": "^3.7.4"
}
}
The command I am running is: pkg package.json and it seems to run without any error. However, when running the binary I have similar errors:
error: Error: Cannot find module 'esprima'
Require stack:
- aesprim
1) If you want to compile the package/file into executable, please pay attention to compilation warnings and specify a literal in 'require' call. 2) If you don't want to compile the package/file into executable and want to 'require' it from filesystem (likely plugin), specify an absolute path in 'require' call using process.cwd() or process.execPath.
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
at Function._resolveFilename (pkg/prelude/bootstrap.js:1955:46)
at Function.resolve (internal/modules/cjs/helpers.js:107:19)
at Object.<anonymous> (/snapshot/app/node_modules/jsonpath/lib/aesprim.js:4:20)
at Module._compile (pkg/prelude/bootstrap.js:1930:22)
at Object.<anonymous> (/snapshot/app/node_modules/jsonpath/lib/aesprim.js:15:11)
at Module._compile (pkg/prelude/bootstrap.js:1930:22)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ 'aesprim' ],
pkg: true
},
I tried to install esprima manually and create the package again, but the error is the same.
Thanks for your help

Npm update or installing packages breaks the compiler

I have a recent project that my working on it.
I installed a vue package and the npm compiler broke, it cant compile anymore. I tried with other packages and always happens the same (or updating).
Error : npm WARN extract-text-webpack-plugin#3.0.2 requires a peer of webpack#^3.1.0 but none is installed. You must install peer dependencies yourself.
Also in the github page : [DEPRECATED] Please use https://github.com/webpack-contrib/mini-css-extract-plugin Extracts text from a bundle into a separate file
This happens from nowhere. Friday this was working fine.
Packages installed friday : purgecss , vue-instantsearch and algoliasearch.
After the npm update : the command npm run watch works but the app.css file has JS in it, very weird. The npm run production no longer works.
Error :
> cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js
SyntaxError: Unexpected token � in JSON at position 0
at JSON.parse (<anonymous>)
at Object.parseSourceMapInput (C:\server\htdocs\myproject\node_modules\postcss\node_modules\source-map\lib\util.js:433:15)
at new SourceMapConsumer (C:\server\htdocs\myproject\node_modules\postcss\node_modules\source-map\lib\source-map-consumer.js:17:22)
at PreviousMap.consumer (C:\server\htdocs\myproject\node_modules\postcss\lib\previous-map.js:69:28)
at new Input (C:\server\htdocs\myproject\node_modules\postcss\lib\input.js:93:22)
at parse (C:\server\htdocs\myproject\node_modules\postcss\lib\parse.js:13:15)
at new LazyResult (C:\server\htdocs\myproject\node_modules\postcss\lib\lazy-result.js:60:16)
at Processor.<anonymous> (C:\server\htdocs\myproject\node_modules\postcss\lib\processor.js:138:12)
at Processor.process (C:\server\htdocs\myproject\node_modules\postcss\lib\processor.js:117:23)
at Function.creator.process (C:\server\htdocs\myproject\node_modules\postcss\lib\postcss.js:148:43)
at OptimizeCssAssetsWebpackPlugin.processCss (C:\server\htdocs\myproject\node_modules\optimize-css-assets-webpack-plugin\src\index.js:73:21)
at Object.processor (C:\server\htdocs\myproject\node_modules\optimize-css-assets-webpack-plugin\src\index.js:13:18)
at C:\server\htdocs\myproject\node_modules\last-call-webpack-plugin\src\index.js:150:10
at arrayEach (C:\server\htdocs\myproject\node_modules\lodash\_arrayEach.js:15:9)
at forEach (C:\server\htdocs\myproject\node_modules\lodash\forEach.js:38:10)
at OptimizeCssAssetsWebpackPlugin.process (C:\server\htdocs\myproject\node_modules\last-call-webpack-plugin\src\index.js:147:5)
at C:\server\htdocs\myproject\node_modules\last-call-webpack-plugin\src\index.js:178:28
at _next0 (eval at create (C:\server\htdocs\myproject\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:9:17)
at eval (eval at create (C:\server\htdocs\myproject\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:25:1)
at C:\server\htdocs\myproject\node_modules\terser-webpack-plugin\dist\index.js:321:9
at step (C:\server\htdocs\myproject\node_modules\terser-webpack-plugin\dist\TaskRunner.js:87:9)
at done (C:\server\htdocs\myproject\node_modules\terser-webpack-plugin\dist\TaskRunner.js:98:30)
at tryCatcher (C:\server\htdocs\myproject\node_modules\bluebird\js\release\util.js:16:23)
at Promise._settlePromiseFromHandler (C:\server\htdocs\myproject\node_modules\bluebird\js\release\promise.js:547:31)
at Promise._settlePromise (C:\server\htdocs\myproject\node_modules\bluebird\js\release\promise.js:604:18)
at Promise._settlePromise0 (C:\server\htdocs\myproject\node_modules\bluebird\js\release\promise.js:649:10)
at Promise._settlePromises (C:\server\htdocs\myproject\node_modules\bluebird\js\release\promise.js:729:18)
at Promise._fulfill (C:\server\htdocs\myproject\node_modules\bluebird\js\release\promise.js:673:18)
at Promise._resolveCallback (C:\server\htdocs\myproject\node_modules\bluebird\js\release\promise.js:466:57)
at Promise._settlePromiseFromHandler (C:\server\htdocs\myproject\node_modules\bluebird\js\release\promise.js:559:17)
at Promise._settlePromise (C:\server\htdocs\myproject\node_modules\bluebird\js\release\promise.js:604:18)
at Promise._settlePromise0 (C:\server\htdocs\myproject\node_modules\bluebird\js\release\promise.js:649:10)
at Promise._settlePromises (C:\server\htdocs\myproject\node_modules\bluebird\js\release\promise.js:729:18)
at Promise._fulfill (C:\server\htdocs\myproject\node_modules\bluebird\js\release\promise.js:673:18)
at Promise._resolveCallback (C:\server\htdocs\myproject\node_modules\bluebird\js\release\promise.js:466:57)
at Promise._settlePromiseFromHandler (C:\server\htdocs\myproject\node_modules\bluebird\js\release\promise.js:559:17)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! # production: `cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the # production script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Package.json
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "npm run development -- --watch",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --disable-host-check --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"lint": "eslint --fix --ext .js,.vue resources/js"
},
"dependencies": {
"#fortawesome/fontawesome-svg-core": "^1.2.17",
"#fortawesome/free-brands-svg-icons": "^5.8.1",
"#fortawesome/free-regular-svg-icons": "^5.8.1",
"#fortawesome/free-solid-svg-icons": "^5.8.1",
"#fortawesome/vue-fontawesome": "^0.1.6",
"#inotom/vue-go-top": "^1.1.0",
"algoliasearch": "^3.35.1",
"axios": "^0.18.1",
"bootstrap": "^4.3.1",
"instantsearch.css": "^7.3.1",
"jquery": "^3.4.1",
"js-cookie": "^2.2.0",
"popper.js": "^1.15.0",
"sweetalert2": "^8.10.0",
"v-tooltip": "^2.0.2",
"vform": "^1.0.0",
"vue": "^2.6.10",
"vue-awesome-swiper": "^3.1.3",
"vue-content-loader": "^0.2.2",
"vue-foldable": "^1.0.0",
"vue-fuse": "^2.1.2",
"vue-i18n": "^8.11.2",
"vue-instantsearch": "^2.6.0",
"vue-lazyload": "^1.3.3",
"vue-loading-overlay": "^3.2.0",
"vue-lodash": "^2.0.2",
"vue-meta": "^1.6.0",
"vue-notification": "^1.3.20",
"vue-observe-visibility": "^0.4.6",
"vue-router": "^3.0.6",
"vue-slider-component": "^3.0.42",
"vue-slim-tabs": "^0.4.0",
"vuelidate": "^0.7.4",
"vuex": "^3.1.0",
"vuex-router-sync": "^5.0.0"
},
"devDependencies": {
"#babel/plugin-syntax-dynamic-import": "^7.2.0",
"#babel/preset-env": "^7.4.4",
"babel-eslint": "^10.0.1",
"cross-env": "^5.2.0",
"eslint": "^5.16.0",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-import": "^2.17.2",
"eslint-plugin-node": "^9.0.1",
"eslint-plugin-promise": "^4.1.1",
"eslint-plugin-standard": "^4.0.0",
"eslint-plugin-vue": "^5.2.2",
"extract-text-webpack-plugin": "^3.0.2",
"glob-all": "^3.1.0",
"laravel-mix": "^4.0.15",
"laravel-mix-versionhash": "^1.0.7",
"purgecss-webpack-plugin": "^1.6.0",
"resolve-url-loader": "^2.3.1",
"sass": "^1.20.1",
"sass-loader": "^7.1.0",
"vue-template-compiler": "^2.6.10",
"webpack-bundle-analyzer": "^3.3.2"
}
}
if i remove the extract-text-webpack-plugin and install mini-css-extract-plugin :
C:\server\htdocs\myproject\node_modules\webpack-cli\bin\cli.js:93
throw err;
^
Error: Cannot find module 'extract-text-webpack-plugin'
Require stack:
- C:\server\htdocs\myproject\node_modules\laravel-mix-versionhash\src\index.js
- C:\server\htdocs\myproject\webpack.mix.js
- C:\server\htdocs\myproject\node_modules\laravel-mix\setup\webpack.config.js
- C:\server\htdocs\myproject\node_modules\webpack-cli\bin\utils\convert-argv.js
- C:\server\htdocs\myproject\node_modules\webpack-cli\bin\cli.js
- C:\server\htdocs\myproject\node_modules\webpack\bin\webpack.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:797:15)
at Function.Module._load (internal/modules/cjs/loader.js:690:27)
at Module.require (internal/modules/cjs/loader.js:852:19)
at require (C:\server\htdocs\myproject\node_modules\v8-compile-cache\v8-compile-cache.js:161:20)
at Object.<anonymous> (C:\server\htdocs\myproject\node_modules\laravel-mix-versionhash\src\index.js:7:27)
at Module._compile (C:\server\htdocs\myproject\node_modules\v8-compile-cache\v8-compile-cache.js:192:30)
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 Module.require (internal/modules/cjs/loader.js:852:19)
at require (C:\server\htdocs\myproject\node_modules\v8-compile-cache\v8-compile-cache.js:161:20)
at Object.<anonymous> (C:\server\htdocs\myproject\webpack.mix.js:4:1)
at Module._compile (C:\server\htdocs\myproject\node_modules\v8-compile-cache\v8-compile-cache.js:192:30)
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 Module.require (internal/modules/cjs/loader.js:852:19)
at require (C:\server\htdocs\myproject\node_modules\v8-compile-cache\v8-compile-cache.js:161:20)
at Object.<anonymous> (C:\server\htdocs\myproject\node_modules\laravel-mix\setup\webpack.config.js:12:1)
at Module._compile (C:\server\htdocs\myproject\node_modules\v8-compile-cache\v8-compile-cache.js:192:30)
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 Module.require (internal/modules/cjs/loader.js:852:19)
at require (C:\server\htdocs\myproject\node_modules\v8-compile-cache\v8-compile-cache.js:161:20)
at WEBPACK_OPTIONS (C:\server\htdocs\myproject\node_modules\webpack-cli\bin\utils\convert-argv.js:114:13)
at requireConfig (C:\server\htdocs\myproject\node_modules\webpack-cli\bin\utils\convert-argv.js:116:6)
at C:\server\htdocs\myproject\node_modules\webpack-cli\bin\utils\convert-argv.js:123:17
at Array.forEach (<anonymous>)
at module.exports (C:\server\htdocs\myproject\node_modules\webpack-cli\bin\utils\convert-argv.js:121:15)
at C:\server\htdocs\myproject\node_modules\webpack-cli\bin\cli.js:71:45
at Object.parse (C:\server\htdocs\myproject\node_modules\webpack-cli\node_modules\yargs\yargs.js:567:18)
at C:\server\htdocs\myproject\node_modules\webpack-cli\bin\cli.js:49:8
at Object.<anonymous> (C:\server\htdocs\myproject\node_modules\webpack-cli\bin\cli.js:366:3)
at Module._compile (internal/modules/cjs/loader.js:959:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10) {
code: 'MODULE_NOT_FOUND',
webpack.mix.js
const path = require('path')
const fs = require('fs-extra')
const mix = require('laravel-mix')
require('laravel-mix-versionhash')
// const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
const PurgecssPlugin = require('purgecss-webpack-plugin')
const glob = require('glob-all')
mix
.js('resources/js/app.js', 'public/dist/js')
.sass('resources/sass/app.scss', 'public/dist/css')
.disableNotifications()
if (mix.inProduction()) {
mix.versionHash()
} else {
mix.sourceMaps()
}
mix.webpackConfig({
plugins: [
// new BundleAnalyzerPlugin()
new PurgecssPlugin({
paths: glob.sync([
path.join(__dirname, 'resources/js/**/*.vue'),
path.join(__dirname, 'resources/js/**/*.js')
])
}),
],
resolve: {
extensions: ['.js', '.json', '.vue'],
alias: {
'~': path.join(__dirname, './resources/js')
}
},
output: {
chunkFilename: 'dist/js/[chunkhash].js',
path: mix.config.hmr ? '/' : path.resolve(__dirname, './public/build')
}
})
mix.then(() => {
if (!mix.config.hmr) {
process.nextTick(() => publishAseets())
}
})
function publishAseets () {
const publicDir = path.resolve(__dirname, './public')
if (mix.inProduction()) {
fs.removeSync(path.join(publicDir, 'dist'))
}
fs.copySync(path.join(publicDir, 'build', 'dist'), path.join(publicDir, 'dist'))
fs.removeSync(path.join(publicDir, 'build'))
}

nodejs: SyntaxError: Unexpected identifier

I'm taking a look at https://github.com/intoli/remote-browser. I'm working in win10 with node 11.5. I've followed the instructions at the bottom of the repo:
# Clone the repository.
git clone https://github.com/intoli/remote-browser.git
cd remote-browser
# Install the dependencies.
yarn install
# Build the project.
yarn build
# Run the tests.
yarn test
Now when I try to run it using :
$ node src/index.js
E:\ENVS\js\remote-browser\src\index.js:1
(function (exports, require, module, __filename, __dirname) { import Browser from './browser';
^^^^^^^
SyntaxError: Unexpected identifier
at new Script (vm.js:83:7)
at createScript (vm.js:267:10)
at Object.runInThisContext (vm.js:319:10)
at Module._compile (internal/modules/cjs/loader.js:684:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:774:12)
at executeUserCode (internal/bootstrap/node.js:342:17)
How can I get this working?
edit index.js:
import Browser from './browser';
import ConnectionProxy from './connections/proxy';
export default Browser;
export { Browser };
export { ConnectionProxy };
export * from './errors';
export * from './launchers';
edit2:
{
"name": "remote-browser",
"version": "0.0.15",
"description": "A low-level browser automation framework built on top of the Web Extensions API standard. ",
"main": "index.js",
"repository": "git#github.com:intoli/remote-browser.git",
"author": "Intoli, LLC <contact#intoli.com>",
"license": "BSD",
"scripts": {
"build": "Set NODE_ENV=production webpack --config webpack",
"build:web": "NODE_ENV=production webpack --config webpack/web-client.config.js",
"postversion": "git push && git push --tags",
"test": "npm run build && NODE_ENV=test mocha --exit --require babel-core/register",
"test-fast": "NODE_ENV=test mocha --exit --require babel-core/register --invert --grep Browser",
"watch": "NODE_ENV=development webpack --watch --config webpack"
},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-eslint": "^8.0.2",
"babel-loader": "^7.1.2",
"babel-plugin-transform-builtin-extend": "^1.1.2",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.6.1",
"clean-webpack-plugin": "^0.1.17",
"copy-webpack-plugin": "^4.2.1",
"eslint": "^4.11.0",
"eslint-config-airbnb": "^16.1.0",
"eslint-loader": "^1.9.0",
"eslint-plugin-import": "^2.8.0",
"imports-loader": "^0.7.1",
"jimp": "^0.2.28",
"mocha": "^4.0.1",
"null-loader": "^0.1.1",
"source-map-support": "^0.5.0",
"webextension-polyfill": "^0.2.1",
"webpack": "^3.8.1",
"webpack-chrome-extension-reloader": "^0.6.6"
},
"dependencies": {
"chromedriver": "^2.37.0",
"express": "^4.16.2",
"express-ws": "^3.0.0",
"geckodriver": "^1.11.0",
"isomorphic-fetch": "^2.2.1",
"portfinder": "^1.0.13",
"selenium-webdriver": "^4.0.0-alpha.1",
"simple-websocket": "^5.1.0",
"ws": "^3.3.2"
}
}
You can't run node src/index.js. When you run yarn build it will create a new folder dist in the root folder, which has all the source code. Go to this folder and find the index.js file, open this to learn more.

Uncaught Error: Cannot find module './charset.js'

Why am I getting this error?
Uncaught Error: Cannot find module './charset.js'
package.json
{
"name": "app",
"version": "1.0.0",
"description": "Application built with Flux and React.js",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Joe Collins",
"license": "",
"devDependencies": {
"browserify": "*",
"flux": "*",
"gulp": "*",
"reactify": "*",
"vinyl-source-stream": "*",
"object-assign": "*"
},
"dependencies": {
"bufferutil": "^1.2.1",
"charset": "^1.0.0",
"http": "0.0.0",
"react": "^0.14.7",
"react-dom": "^0.14.7",
"socket.io": "^1.4.5",
"utf-8-validate": "^1.2.1"
}
}
gulpfile.js
var gulp = require('gulp');
var browserify = require('browserify');
var reactify = require('reactify');
var source = require('vinyl-source-stream');
gulp.task('browserify', function() {
browserify('./src/js/main.js')
.transform('reactify')
.bundle()
.pipe(source('main.js'))
.pipe(gulp.dest('dist/js'))
});
gulp.task('copy', function() {
gulp.src('src/index.html')
.pipe(gulp.dest('dist'));
gulp.src('src/css/*.*')
.pipe(gulp.dest('dist/css'));
gulp.src('src/js/vendors/*.*')
.pipe(gulp.dest('dist/js'));
});
gulp.task('default', ['browserify', 'copy'], function() {
return gulp.watch('src/**/*.*', ['browserify', 'copy']);
});
App.js
var io = require('socket.io')();
You have to use socket.io-client for client side stuff. I have a hunch that charset.js uses a binary, or something that can't be converted to the browser.
https://github.com/socketio/socket.io-client
I was facing same problem but with some other module I did reinstall with latest and it is working for me
Problem
Error: Cannot find module './charset.js'
1) If you want to compile the package/file into executable, please pay attention to compilation warnings and specify a literal in 'require' call. 2) If you don't want to compile the package/file into executable and want to 'require' it from filesystem (likely plugin), specify an absolute path in 'require' call using process.cwd() or process.execPath.
at Function.Module._resolveFilename (module.js:534:15)
at Function.Module._resolveFilename (pkg/prelude/bootstrap.js:1269:46)
at Function.Module._load (module.js:464:25)
at Module.require (module.js:577:17)
at Module.require (pkg/prelude/bootstrap.js:1153:31)
at require (internal/module.js:11:18)
at /snapshot/html/config/configurator-file-api/node_modules/accepts/node_modules/negotiator/lib/negotiator.js:21:16
at Array.forEach (<anonymous>)
at Object.<anonymous> (/snapshot/html/config/configurator-file-api/node_modules/accepts/node_modules/negotiator/lib/negotiator.js:19:18)
at Module._compile (pkg/prelude/bootstrap.js:1243:22)
at Object.Module._extensions..js (module.js:644:10)
at Module.load (module.js:552:32)
at tryModuleLoad (module.js:495:12)
at Function.Module._load (module.js:487:3)
at Module.require (module.js:577:17)
at Module.require (pkg/prelude/bootstrap.js:1153:31)
Solution
cd /var/html/config/configurator-file-api/node_modules/accepts/
npm uninstall negotiator --save
npm install negotiator --save
Yes it is working

Categories

Resources