Skip to content

Error: Unexpected token when importing axios -- node-resolve should be first #66

@JWMB

Description

@JWMB
[!] Error: Unexpected token
node_modules\axios\package.json (2:9)
1: {
2:   "_from": "axios",
            ^

Same error as when importing axios into pure ES6 project and not having set browser: true for rollup-plugin-node-resolve. Simple test case: single js file containing

import axios from "axios";
window.process = window.process || { env: {} };
axios.get("http://httpbin.org/").then(response => console.log("Got length: " + response.data.length));

Using the below rollup.config.js produces the error, but when excluding rollup-plugin-typescript2 it works.

Versions

  • node: 8.9.4
  • typescript: 2.7.2
  • rollup: 0.57.1
  • rollup-plugin-typescript2: 0.12.0

rollup.config.js

import typescript from 'rollup-plugin-typescript2';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';

export default {
	input: 'src/main.js',
	output: {
		file: 'public/bundle.js',
		format: 'iife',
		sourcemap: true
	},
	plugins: [
		typescript(),
		resolve({ browser: true }),
		commonjs()
	]
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    problem: plugin orderThe plugin order in this issue seems incompatible. See the "Compatibility" section in the READMEscope: docsDocumentation could be improved. Or changes that only affect docsscope: integrationRelated to an integration, not necessarily to core (but could influence core)scope: upstreamIssue in upstream dependencysolution: out-of-scopeThis is out of scope for this projectsolution: tsc behaviorThis is tsc's behavior as well, so this is not a bug with this plugin

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions