node-summary icon indicating copy to clipboard operation
node-summary copied to clipboard

summary.js import statements causing error

Open kingychiu opened this issue 7 years ago • 16 comments

The import statements in the summary.js causing error:

import _ from 'lodash'
import Tokenizer from 'sbd'
import request from 'request'
(function (exports, require, module, __filename, __dirname) { import _ from 'lodash'
                                                              ^^^^^^
SyntaxError: Unexpected token import

node version: v6.11.1

kingychiu avatar Aug 24 '17 03:08 kingychiu

Same here node: '7.2.1',

gg4u avatar Sep 19 '17 19:09 gg4u

v7.6.0 shows this error as well...

LAMike310 avatar Sep 26 '17 20:09 LAMike310

Works fine on v8.5.0

fungilation avatar Sep 26 '17 20:09 fungilation

@fungilation Upgraded to 8.5.0, and still getting an error, using "node-summary": "^1.2.0", in my package.json

LAMike310 avatar Sep 26 '17 21:09 LAMike310

Curious, try switching to my fork? I don't want some PRs merged to master here so my app is using my fork still, and it works fine for me on latest node. If it works for you too then we know it's something in master recently that went wrong.

fungilation avatar Sep 26 '17 21:09 fungilation

I'm on node 8.7.0 - this doesn't work yet without enabling module support and using a .mjs extension. Anyways @jbrooksuk are you open to accepting a pr which builds and publishes the transpiled source?

michaelBenin avatar Oct 17 '17 01:10 michaelBenin

I'm not sure what's the cause of import issues. I'm on node 8.7 and using in my React Native app without issue. For reference in debugging, this is my package.json:

{
  "name": "APP",
  "version": "0.0.1",
  "private": true,
  "eslintConfig": {
    "parserOptions": {
      "ecmaVersion": 6,
      "sourceType": "module",
      "ecmaFeatures": {
        "jsx": true,
        "experimentalObjectRestSpread": true
      }
    },
    "env": {
      "browser": true,
      "node": true
    },
    "plugins": [
      "react",
      "react-native"
    ],
    "rules": {
      "comma-dangle": [
        2,
        "always-multiline"
      ],
      "semi": [
        2,
        "never"
      ],
      "react-native/no-unused-styles": 2,
      "react-native/split-platform-components": 2
    }
  },
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start"
  },
  "dependencies": {
    "babel-plugin-idx": "^2",
    "he": "^1.1.0",
    "jssha": "^2.3.1",
    "lodash": "^4.17.2",
    "moment-timezone": "^0.5.10",
    "node-summary": "../node-summary",
    "react": "16.0.0-beta.5",
    "react-native": "0.49.3",
    "react-native-blur": "^3.1",
    "react-native-code-push": "5.1.3-beta",
    "react-native-firebase": "^3.0",
    "react-native-fit-image": "^1.4.8",
    "react-native-highlight-words": "smartkarma/react-native-highlight-words",
    "react-native-keep-awake": "envoy/react-native-keep-awake",
    "react-native-linear-gradient": "^2.0.0",
    "react-native-modalbox": "^1.3.8",
    "react-native-notification": "../react-native-notification",
    "react-native-orientation": "^3.0.0",
    "react-native-parallax-scroll-view": "../react-native-parallax-scroll-view",
    "react-native-safari-view": "^2.0.0",
    "react-native-sentry": "^0.28.0",
    "react-native-status-bar-size": "^0.3.2",
    "react-native-swiper": "^1.5.10",
    "react-native-tooltip": "../react-native-tooltip",
    "react-native-tts": "^1.3.0",
    "react-native-vector-icons": "^4.1.1",
    "react-native-webview-bridge": "../react-native-webview-bridge-RN0.40",
    "react-redux": "^5.0.1",
    "redux": "^3.6.0",
    "redux-thunk": "^2.1.0"
  },
  "devDependencies": {
    "redux-logger": "^3.0.6"
  },
  "resolutions": {
    "moment-timezone/moment": "^2.19.0"
  }
}

$ react-native info

Scanning folders for symlinks in [APP_ROOT]/node_modules (37ms)

Environment:
  OS:  macOS Sierra 10.12.6
  Node:  8.7.0
  Yarn:  1.2.1
  npm:  5.4.2
  Watchman:  4.9.0
  Xcode:  Xcode 9.0 Build version 9A235
  Android Studio:  Not Found

Packages: (wanted => installed)
  react: 16.0.0-beta.5 => 16.0.0-beta.5
  react-native: 0.49.3 => 0.49.3

fungilation avatar Oct 17 '17 02:10 fungilation

@fungilation this is because you are transpiling the source with babel. It breaks with pure node. Try it in a project that doesn't transpile.

michaelBenin avatar Oct 17 '17 14:10 michaelBenin

the same problems here

minhdtb avatar Oct 23 '17 07:10 minhdtb

I just tried with the master branch today, and got the same error.

johnking avatar Jan 16 '18 18:01 johnking

@jbrooksuk would you accept a PR changing to point at the transpiled js?

michaelBenin avatar Jan 16 '18 20:01 michaelBenin

My workaround is that I created my own local module with rollup.

johnking avatar Jan 16 '18 23:01 johnking

For anyone interested, as a quick fix I just transpiled it to a local file with a basic webpack config

const path = require('path');
module.exports = {
  mode: "development",
  optimization: {
    minimize: false
  },
  target: 'node',
  entry: './node_modules/node-summary/index.js',
  output: {
    path: path.join(__dirname),
    filename: 'node-summary.js',
    library: 'node-summary',
    libraryTarget: 'commonjs2'
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        loader: 'babel-loader',
      },
    ]
  }
}

Save this to webpack.config.js and run webpack it'll save to node-summary.js

jawerty avatar Jul 02 '18 07:07 jawerty

You need to ship the transpiled code in the published module rather than the raw code. babel won't transpile code under the node_modules folder by default so it needs to be done by the library publisher before publishing to npm.

justinmchase avatar Aug 08 '18 23:08 justinmchase

let _ = require('lodash')
let Tokenizer = require('sbd')
let request = require('request')

Jessense avatar Feb 19 '19 08:02 Jessense

I created a pull request fixing this issue(https://github.com/jbrooksuk/node-summary/pull/50). You can use that instead the main package by using the command (or just wait him fix the issue / or merge the PR): npm install https://github.com/TroniPM/node-summary

TroniPM avatar Sep 30 '20 04:09 TroniPM