Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

summary.js import statements causing error #36

Open
kingychiu opened this issue Aug 24, 2017 · 16 comments
Open

summary.js import statements causing error #36

kingychiu opened this issue Aug 24, 2017 · 16 comments

Comments

@kingychiu
Copy link

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

@gg4u
Copy link

gg4u commented Sep 19, 2017

Same here node: '7.2.1',

@LAMike310
Copy link

v7.6.0 shows this error as well...

@fungilation
Copy link
Contributor

Works fine on v8.5.0

@LAMike310
Copy link

LAMike310 commented Sep 26, 2017

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

@fungilation
Copy link
Contributor

fungilation commented Sep 26, 2017

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.

@michaelBenin
Copy link
Contributor

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 michaelBenin mentioned this issue Oct 17, 2017
@fungilation
Copy link
Contributor

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

@michaelBenin
Copy link
Contributor

@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.

@minhdtb
Copy link

minhdtb commented Oct 23, 2017

the same problems here

@johnking
Copy link

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

@michaelBenin
Copy link
Contributor

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

@johnking
Copy link

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

@jawerty
Copy link

jawerty commented Jul 2, 2018

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

@justinmchase
Copy link

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.

@Jessense
Copy link

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

@TroniPM
Copy link

TroniPM commented Sep 30, 2020

I created a pull request fixing this issue(#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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests